patB1043 输出PATest

注意:字符串长度的确定要放在循环体外。这样会减少运行的时间。

#include <iostream>

#include <cstdio>
#include <cstring> 
using namespace std;
char strT[6]={'P','A','T','e','s','t'};
int hashT[6]={0};
int main(int argc, char** argv) {
char str[10010];
gets(str);
int sum=0,len=strlen(str);
for(int i=0;i<len;i++){            //maxnum=1000*6     **长度的测量放在外面。 
for(int u=0;u<6;u++){
if(str[i]==strT[u]){
hashT[u]++;
sum++;
}
}  
}
while(sum!=0){
for(int j=0;j<6;j++){
if(hashT[j]!=0){
printf("%c",strT[j]);
hashT[j]--;
sum--;
}
}
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37816373/article/details/80165817