toj1856 Anagrammatic Distance

题目链接:http://acm.tju.edu.cn/toj/showp.php?pid=1856

题目大意:找出两个字符串中所有相同的字母,必须一对一,不能一对二

思路:简单题,记下来是因为发现了有趣的事情: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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值