文章
1
粉丝
0
获赞
5
访问
166
若直接while(1),再循环内处理输入则会时间/输出超限。
将以下部分:
while(1){
cin.getline(sp, 10)
if(sp[0]=='#') break;
cin.getline(str, 100);
。。。。。
改为:
#include <cstring>
#include <iostream>
using namespace std;
void test()
{
char sp[10];
char str[100];
string n1, n2;
while(cin.getline(sp, 10)){
if(sp[0]=='#') break;
cin.getline(str, 100);
int counti=0;
for(int i=0; i<strlen(sp); i++){
for(int j =0; j<strlen(str); j++){
if(str[j]==sp[i]) ++counti;
}
cout<<sp[i]<<' '<<counti<<endl;
counti = 0;
}
}
}
int main(){test();return 0;}
即可
登录后发布评论
暂无评论,来抢沙发