标签:
一道简单的模拟题,处理起来还不算太简单,另外在读入时注意用getchar(),用scanf很有可能会超时
#include <cstdio> #include <cstring> const int maxn = 100000+2; char str[maxn],s[maxn]; int a[maxn]; int main() { int T,t=1; scanf("%d",&T); while(T--) { getchar(); int n,len=0; while(1) { str[len] = getchar(); len++; if(str[len-1] == '\n') break; } len -= 1; scanf("%d",&n); int Mod = len%n; int length = len/n; int tot = 0; int tmp = Mod,x = 0; //printf("%d %d\n",tmp,len); for(int i=0; i<n; i++) { a[i] = x; if(tmp) { x += length+1; tmp--; } else x += length; } //for(int i=0; i<n; i++) printf("%d ",a[i]); for(int i=0; i<length; i++) for(int j=0; j<n; j++) s[tot++] = str[a[j]+i]; for(int i=0; i<Mod; i++) s[tot++] = str[a[i]+length]; s[tot] = '\0'; printf("Case #%d:\n%s\n",t++,s); } }
标签:
原文地址:http://blog.csdn.net/raalghul/article/details/51366270