PAT (Basic Level) Practice (中文)
1043 输出PATest (20分)
#include<stdio.h>
#define maxSize 10001
int main()
{
char s[maxSize];
int count[200]={};
char dic[]="PATest";
gets(s);
for(int i=0;s[i]!='\0';++i)
++count[(int)s[i]];
while(1)
{
int flag=0;
for(int i=0;dic[i]!='\0';++i)
{
if(count[(int)dic[i]]>0)
{
printf("%c",dic[i]);
--count[(int)dic[i]];
flag=1;
}
}
if(flag==0)
break;
}
return 0;
}
PAT (Advanced Level) Practice
1092 To Buy or Not to Buy (20分)
#include<stdio.h>
int main()
{
int counts[123]={};
char seller[1001];
char Eva[1001];
gets(seller);
gets(Eva);
for(int i=0;seller[i]!='\0';i++)
++counts[(int)seller[i]];
for(int i=0;Eva[i]!='\0';i++)
--counts[(int)Eva[i]];
int count = 0;
for(int i=0;i<123;i++)
{
if(counts[i]<0)
count+=counts[i];
}
if(count<0)
{
printf("No %d",-count);
}
else
{
count = 0;
for(int i=0;i<123;i++)
if(counts[i]>0)
count+=counts[i];
printf("Yes %d",count);
}
return 0;
}