| ||||||||||
| 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 | |||||||||
实在无法,求救,老是RUNTIME ERROR,帮帮我各位大神。代码如下#include <iostream>
#include <cstring>
#define Maxsize 300
void Search(int i,int a[Maxsize],char ch,int k);
char c[Maxsize];
using namespace std;
int main()
{
int n,a[Maxsize],k,i;
char b[Maxsize];
while(cin >> n, n != 0)
{
for(i=1;i<=n;i++)
cin>>a[i];
while(cin >> k, k != 0)
{
//memset(b,' ',sizeof(b));
for(i=0;i<1000;i++)//初始化b
b[i]=' ';
gets(b);
for(i=1;i<=n;i++)//每个位置操作
Search(i,a,b[i],k);
for(i=1;i<=n;i++)//输出编码
cout<<c[i];
cout<<endl;
}
cout<<endl;
}
return 0;
}
void Search(int i,int a[Maxsize],char ch,int k)//判断循环次数并寻找正确位置
{
int d[Maxsize];
int pos=0,first=a[i],j=1;
d[1]=a[i];
do{
d[++j]=a[d[j]];
pos++;
}while(d[j]!=first);//找到一周要循环几次
if(k%pos)
c[d[k%pos]]=ch;//存放编码位置
else
c[d[pos]]=ch;//存放编码位置
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator