题解 | #输出指定长度子串#C++暴力遍历解法
输出指定长度子串
https://www.nowcoder.com/practice/56c6fb8231a44ed8ab91ac231f7b2c63
#include <iostream> using namespace std; int main() { string a; cin>>a; int i=0; int j=0; int n=0; cin>>n; int len=a.size(); if(len-n<0 || n<=0) { cout<<-1; } else { for(i=0;i<=len-n;i++) { for(j=0;j<n;j++) { cout<<a[i+j]; } if(i!=len-n) { cout<<" "; } } } return 0; }