#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stack>
#include <queue>
#include <string>
#include <string.h>
#define FOR(i,n) for (int (i)=0;(i)<(n);(i)++)
#define elif else if
#define INF 1000000000
using namespace std;
int main () {
int N=3;
string a="1 2 3 4 5 6 7 8 9";
char str[] = " ";
int pos=0,lastpos=0;
int index = 0;
int lastidx = 1;
cout << a[0]<<‘ ‘;
while(1) {
pos = a.find (str, lastpos + 1);
index++;
if (index == lastidx + N + 1) {
lastidx = index;
if (pos == -1) {
cout << a[lastpos + 1, a.length () - 1] <<‘ ‘;
break;
}
cout << a[lastpos + 1, pos - 1]<<‘ ‘;
}
if (pos == -1) break;
lastpos = pos;
}
return 0;
}
原文地址:http://blog.csdn.net/qq_21970857/article/details/46536871