2009-01-15 16:06:11來源不明
2006 NPSC E. 達文西密碼
其實我不知道為什麼要跑1000個,我原本用strlen(y)結果答案錯!
/***********************************************************/
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- main()
- {
- int a,b,c,d,temp=0,time=0;
- char x[1000],y[1000];
- while(gets(x))
- {
- temp=0;time=0;
- gets(y);
- a=strlen(x);
- d=strlen(y);
- for(b=0;b<a;b++)
- {
- if(x[b]!=' ')
- {
- time++;
- for(c=0;c<d;c++)
- {
- if(y[c]==x[b])
- {
- y[c]=-1;
- temp++;
- break;
- }
- }
- }
- }
- if(time==temp)
- printf("Yes\n");
- else
- printf("No\n");
- }
- return 0;
- }
/***********************************************/
陣列加快版
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
int a,b,c,d,e,n,temp=0,time=0;
char x[1000],y[1000];
while(gets(x))
{
gets(y);
int num[256][2]={0},m=strlen(x);
for(a=0;a<m;a++)
{
num[x[a]][0]++;
num[y[a]][1]++;
}
for(a=0;a<256;a++)
if(a!=' ')
if(num[a][0]!=num[a][1]) break;
if(a==256) printf("Yes\n");
else printf("No\n");
}
return 0;
}
上一篇:2006 NPSC H. PS3