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 |
为什么我re啊?救命啊!#include <iostream.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #define maxn 3000 int a[maxn]; int d[maxn]; int e[maxn]; char b[maxn]; char c[maxn]; int n; _int64 recursive() { _int64 count=1; int i; for(i=0;i<n;i++) e[i]=a[i]; while(1) { for(i=0;i<n;i++) d[e[i]-1] = i+1; count++; for(i=0;i<n;i++) if(a[i]!=d[i])break; if(n==i) break; else for(i=0;i<n;i++) e[i]=d[i]; } return count; } int main() { _int64 i,j; _int64 k; while(cin>>n && n!=0) { for(i=0;i<n;i++) cin>>a[i]; _int64 kk = recursive();//求循环数; while(1) { gets(c); if(c[0]=='0')break; i=0; while(c[i++]!=' ') continue; c[i-1]='\0'; k = atoi(c); k = (k-1)%kk +1 ; strcpy(b,c+i); for(i=(int)strlen(b); i<n;i++) b[i]=' '; b[n]='\0'; for(i=1;i<=k;i++) { for(j=0;j<n;j++) { c[a[j]-1]=b[j]; } c[n]='\0'; strcpy(b,c); } cout << b<<endl; } cout<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator