| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
碰见字符的就发愁 wa了一下午,本人新手下面的代码很乱。。。不知道哪里错了。题目给的两个数据都输出正确。包括前面后面的空格,模块间回车。算法是用周期求模,可能会超时,不过老是wa。
#include<iostream>
using namespace std;
int main()
{
int a[500];//记录序列
int lis[500]={0};//记录模的大小
int alis[500]={0};//求模之后需要变化的次数
char ch[500]={' '};//记录输入
char last[500]={' '};//对输入加密后
char last2[500]={' '};
int n;
int t;
int m;
int e=1;
cin>>n;
while(n!=0){
for(int ii=1;ii<=n;ii++)
{
cin>>a[ii];
}
cin>>m;
getchar();//吸收一个空格
for(int j=1;j<=n;j++)
{
t=a[j];
while(1)
{
if(a[j]==a[t]){lis[j]++; break;}
else t=a[t];
lis[j]++;
}
}
while(m!=0)
{
for(int d=1;d<=n;d++)
{
alis[d]=m%lis[d];//记录求模
}
while((ch[e]=getchar())!='\n')e++;
ch[e]=' ';//getchar()会把回车读入,所以用空格改之
for(int b=1;b<=n;b++)
{
int k=b;
for( int j=0,w=b;j<alis[b];j++)
{
k=a[w];
w=k;
}
last[k]=ch[b];
}
for(int ww=1;ww<=n;ww++){last2[ww-1]=last[ww];}last2[n]=0;
puts(last2);//反正putchar 和puts都用了 就是wa啊
cin>>m;
getchar();
for(int bb=1;bb<=n;bb++)
{
last[bb]=' ';
ch[bb]=' ';
e=1;
alis[bb]=0;
}
}
for(int iii=1;iii<=n;iii++)
{
lis[iii]=0;
}
cout<<endl;//模块间回车
cin>>n;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator