测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串。注意这里的字符串包含空格,即空格也可能是要求被统计的字符之一。当读到'#'时输入结束,相应的结果不要输出。
对每个测试用例,统计第1行中字符串的每个字符在第2行字符串中出现的次数,按如下格式输出: c0 n0 c1 n1 c2 n2 ... 其中ci是第1行中第i个字符,ni是ci出现的次数。
I THIS IS A TEST i ng this is a long test string #
I 2 i 3 5 n 2 g 2
#include <stdio.h>
#include<string.h>
int main() {
char str[5];
while(gets(str)!=NULL){//循环输入
if(str[0]=='#')break;//跳出循环不输出
else{
char a[80];
gets(a);
for(int i=0;i<strlen(str);i++){
int n=0;
for(int j=0;j<strlen(a);j++){
if(str[i]==a[j])n++;
}
printf("%c %d\n",str[i],n);
}
}
}
return 0;
} #include<stdio.h>
#include<string.h>
int main(void){
char a[100];
char b[100];
char * c;
int tongji[100];
int flag=0,temp,k=0,l=0,jl;
while(flag!=1){
gets(a);
if(l!=0){
temp=0;
for(int i=0;i<jl;i++){
if(c[i]==a[i]){
temp++;
}
}
if(temp==jl){
break;
}
}
l++;
if(a[0]=='#'){
flag=1;
break;
}
gets(b);
int len1=strlen(a);
jl=len1;
int len2=strlen(b);
for(int i=0;i<len1;i++){
temp=0;
for(int j=0;j<len2;j++){
if(b[j]==a[i]){
temp+=1;
}
}
tongji[i]=temp;
}
for(int i=0;i<len1;i++){
printf("%c %d\n",a[i],tongji[i]);
}
c=a;
}
return 0;
} #include <stdio.h>
#include <string.h>
char s[10];
char str[90];
int main()
{
while(fgets(s, 10, stdin) != NULL)
{
if (!strcmp(s, "#\n"))
break;
fgets(str, 90, stdin);
for (size_t i = 0; i < strlen(s) - 1; i++)
{
int cnt = 0;
for (size_t j = 0; j < strlen(str) - 1; j++)
{
if (s[i] == str[j])
cnt++;
}
printf("%c %d\n", s[i], cnt);
}
}
return 0;
} #include <stdio.h>
#include <string.h>
char s[10];
char str[90];
int hash[128];
int main()
{
while(fgets(s, 10, stdin) != NULL)
{
if (!strcmp(s, "#\n"))
break;
fgets(str, 90, stdin);
for (size_t i = 0; i < strlen(str) - 1; i++)
{
hash[(int)str[i]] ++;
}
for (size_t i = 0; i < strlen(s) - 1; i++)
printf("%c %d\n", s[i], hash[(int)s[i]]);
memset(hash, 0, sizeof(hash));
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main(){
char b[80];
char a[80];
char e;
while(gets(a)!=NULL){
gets(b);
for(int i=0;a[i]!='\0';++i)
{ int number=0;
if(a[i]=='#')
break;
for(int j=0;b[j]!='\0';++j)
if (a[i]==b[j])
number++;
printf("%c %d\n",a[i],number);}
}
return 0;
}