题目大意:找出两个字符串中所有相同的字母,必须一对一,不能一对二
思路:简单题,记下来是因为发现了有趣的事情:1、最长的英文单词:pneumonoultramicroscopicsilicovolcanoconiosis :【病理学】硅酸盐沉着病,矽肺病 统计了下:46个字母;2、求重复什么类型的题,flag一如既往的好用;3、gets(s1[]) 前面为什么要有getchar(): 这里getchar是处理 前面输入号码后的回车符的问题。如果没有这个getchar,那scanf后,会有一个回车符存在输入流的缓冲区内,那么再使用gets的时候,就会取得这个回车符,gets会认为输入结束。
代码:
#include <iostream>
#include <cstring>
#include<cstdio>
using namespace std;
int main()
{
int cas,i,j,len1,len2,ans;
char s1[60],s2[60];
int flag[60];
cin>>cas;
getchar(); //头文件:#include<cstdio>
int num = 0;
while(cas--)
{
memset(flag,0,sizeof(flag));
num++;
ans = 0;
gets(s1); //头文件 #include<cstdio>
gets(s2);
len1 = strlen(s1);
len2 = strlen(s2);
for(i=0;i<len1;i++)
for(j=0;j<len2;j++)
{
if(s1[i]==s2[j] && flag[j]==0)
{
ans++;
flag[j]=1;
break;//找到一个就不能再找了 因为是一对一的
}
}
cout<<"Case #"<<num<<": "<<len1+len2-2*ans<<endl;
}
return 0;
}