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阿 找了很久也找不到错误#include<iostream.h> #include<stdio.h> #include<string.h> #include<stdlib.h> int n; int code[201]; int k; int table[201]; void init() { int i,count,rec; memset(table,0,sizeof(table)); for( i=0;i<=n;i++ ) table[i]=code[i]; i=1; while(i<=n) { count=1; while( table[i]!=i ) { table[i]=code[table[i]]; count++; } table[i]=count; i++; } } void encode(char *mes) { int i,temp,j; char output[201]; int offset[201]; for( i=0;i<=n;i++ ) offset[i]=i; memset(output,0,sizeof(output)); i=1; while(i<=n) { temp=k%table[i]; for(j=1;j<=temp;j++) offset[i]=code[offset[i]]; output[offset[i]]=mes[i]; i++; } strcpy(mes,output); for(i=1;i<=n;i++) printf("%c",output[i]); printf("\n"); } int main() { freopen("in.txt","r",stdin); char mes[201]; int i; scanf("%d",&n); while( n!=0 ) { memset(code,0,sizeof(code)); for( i=1;i<=n;i++ ) scanf("%d",&code[i]); init(); scanf("%d",&k); while( k!=0 ) { memset(mes,0,sizeof(mes)); gets(mes); int len=strlen(mes); if( strlen(mes) < n ) for(i=strlen(mes);i<n;i++) mes[i]=' '; encode(mes); scanf("%d",&k); } printf("\n"); scanf("%d",&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