2007浙大复试机试题代码

来源:互联网 发布:《简明python教程》 编辑:程序博客网 时间:2024/06/05 03:33
#include<iostream> 
#include<string.h>
using namespace std; 


int main() 
{      
char s1[10];
char s2[100];
int cnt[10];
while(gets(s1)&&strcmp(s1,"#")!=0)
{
gets(s2);
memset(cnt,0,sizeof(cnt));

int i,j,m,n;
m=strlen(s1);
n=strlen(s2);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(s1[i]==s2[j])
cnt[i]++;
}
}

for(i=0;i<m;i++)
cout<<s1[i]<<" "<<cnt[i]<<endl;
}

return 0;

}

附注:读入信息时使用gets(),gets()读入包括空格在内的整行信息

0 0