poj 2681 字符串

http://poj.org/problem?id=2681

给你任意长度的字符串,找出两串字符中不相同的字符个数(总数)

#include<string>
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    scanf("%d\n",&n);
   string aa,bb;
    int q=0;
    for(int i=1;i<=n;i++)
    {
        int sum=0;
        int a1[51]={0},b1[51]={0};
       getline(cin,aa);
       getline(cin,bb);
       //scanf("%s\n%s",aa,bb);
       int a=aa.length();
       int b=bb.length();
       if(a==0||b==0)
       {
           cout<<"Case #"<<i<<":  "<<max(a,b)<<endl;

       }
       //int sum=0;
       else{
       for(int k=0;k<a;k++)
       {
           for(int j=0;j<b;j++)
                {
                    if(aa[k]==bb[j]&&a1[k]==0&&b1[j]==0)
                    {
                        a1[k]=1;
                        b1[j]=1;
                    }
                }

       }

       for(int k=0;k<a;k++)
       {
           if(a1[k]==0)sum++;
       }
           for(int j=0;j<b;j++)
                {
                    if(b1[j]==0)sum++;

                }

       cout<<"Case #"<<i<<":  "<<sum<<endl;
       }

    }

    return 0;
}
时间: 2024-08-05 08:49:45

poj 2681 字符串的相关文章

poj 3461 字符串单串匹配--KMP或者字符串HASH

http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <cmath> #include <map> #include <queue> using namespace std;

POJ 1200 字符串HASH

题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有NC个不同的字符,所以我们可以把字符串看成是一个NC进制的串,然后计算出字符串的前缀HASH.然后枚举起点判断子串的HASH值是否已经存在.因为有了前缀HASH值,所以转移是O(1)的. #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #in

Power Strings POJ - 2406,字符串hash

题目链接:POJ - 2406 题目描述 定义两个字符串s1和s2的乘积s1*s2为将s1和s2连结起来得到的字符串. 例如:s1="xy",s2="z",那么s1*s2="xyz". 由此可以定义s1的幂次:s1^0="",s1^n=s1*s1^(n-1),n>0. 输入 输入包含多组测试数据. 每组数据由一行构成,包含一个字符串s. 输入数据以"."结束. 输出 对于每组输入数据输出一行,找出最大

POJ 2774 字符串哈希_解题报告

题目:  http://poj.org/problem?id=2774 A - Long Long Message The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days: his mother is getting ill. Being worried about spending so much on railway ticke

poj 3981 字符串替换

字符串替换 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10871   Accepted: 5100 Description 编写一个C程序实现将字符串中的所有"you"替换成"we" Input 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 Output 对于输入的每一行,输出替换后的字符串 Sample Input you are what you do

poj 2503(字符串)

http://poj.org/problem?id=2503 题意:就是翻译,给你一个字典,然后再查找单词,找得到的就输出单词,找不到的输出eh,用Map水题一个,但这个题有点意思的就是输入的问题 1 #include <iostream> 2 #include <map> 3 #include <string> 4 #include <cstdio> 5 6 using namespace std; 7 8 int main() 9 { 10 // fre

poj 2774 字符串哈希求最长公共子串

Long Long Message #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <stack> #include <cmath> #include <map> #include <string&

POJ 3261 字符串上的k次覆盖问题

题目大意: 给定一个数组,求一个最大的长度的子串至少出现过k次 一个子串出现多次,也就是说必然存在2个子串间的前缀长度为所求的值 通过二分答案,通过线性扫一遍,去判断出现次数,也就是说每次遇见一个height[i] , 出现次数就加1,否则重置为1 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 const int N = 20010; 6 i

Spell checker POJ 1035 字符串

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25426   Accepted: 9300 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word