Case #1:
123456789
Case #2:
Hello, welcome to my dream world!
Case #3:
Toodming is best
Case #4:
sokaisan
思路:
这题只要在最后的行看是否满,满的话不用管,不满就要标记起来,不能放数字。这题用了c++getline超时了。。。。
TLE代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
bool vis[100000+50];
char str[100000+50];
int main()
{
#ifdef zsc
freopen("input.txt","r",stdin);
#endif
int n,m,i,j,k,Cas=1;
scanf("%d",&n);
char s[100000+50];
while(n--)
{
cin.get();
memset(vis,0,sizeof(vis));
cin.getline(s,sizeof(s));
int len = strlen(s);
scanf("%d",&m);
printf("Case #%d:\n",Cas++);
k = len/m+(len%m>0?1:0);
j = k*m-1;
if(len%m==0)k=0;
else k = m-len%m;
while(k--)
{
vis[j--] = true;
}
int c = 0;
for(i=0;i<m;++i){
for(j=i;j<len;j+=m){
if(vis[j])break;
str[j] = s[c++];
}
}
for(i=0;i<len;++i){
if(!vis[i])printf("%c",str[i]);
}
printf("\n");
}
return 0;
}
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
bool vis[100000+50];
char str[100000+50];
char s[100000+50];
int main()
{
#ifdef zsc
freopen("input.txt","r",stdin);
#endif
int n,m,i,j,k,Cas=1;
scanf("%d",&n);
while(n--)
{
getchar();
memset(vis,0,sizeof(vis));
gets(s);
int len = strlen(s);
scanf("%d",&m);
printf("Case #%d:\n",Cas++);
k = len/m+((len%m)>0?1:0);
j = k*m-1;
if(len%m==0)k=0;
else k = m-(len%m);
while(k--)
{
vis[j--] = true;
}
int c = 0;
for(i=0;i<m;++i){
for(j=i;j<len;j+=m){
if(vis[j])break;
str[j] = s[c++];
}
}
for(i=0;i<len;++i){
if(!vis[i])printf("%c",str[i]);
}
printf("\n");
}
return 0;
}