标签:puts turn bit fine scanf close targe php tchar
题目链接:hdu 1439 Cipher
题意:
给你一个n元的key,让你将一个字符串置换k次。
题解:
暴力将每个数的循环数找到,然后k%后对应填字符就行了。
1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespace std; 4 5 const int N=300; 6 char s[N],ans[N]; 7 int a[N],rep[N],n,k; 8 9 int main() 10 { 11 while(scanf("%d",&n),n) 12 { 13 F(i,1,n)scanf("%d",a+i),rep[i]=0; 14 F(i,1,n) 15 { 16 int now=i; 17 while(now!=i||!rep[i])now=a[now],rep[i]++; 18 } 19 while(scanf("%d",&k),k) 20 { 21 getchar(); 22 gets(s+1); 23 int flag=0; 24 F(i,1,n) 25 { 26 if(s[i]==0)flag=1; 27 int now=i,tmp=k%rep[i]; 28 while(tmp--)now=a[now]; 29 if(flag)ans[now]=‘ ‘; 30 else ans[now]=s[i]; 31 } 32 ans[n+1]=0; 33 puts(ans+1); 34 } 35 puts(""); 36 } 37 return 0; 38 }
标签:puts turn bit fine scanf close targe php tchar
原文地址:http://www.cnblogs.com/bin-gege/p/7064238.html