标签:des style blog color strong io for 问题
Description
Input
Output
Sample Input
5 3 Inkfish Henry Carp Max Jericho Carp Max Carp 0
Sample Output
3
方法一:
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
#include <ctype.h>
using namespace std;
int main()
{
char str[30];
int len;
int n, m;
int i, j;
map<string,int>ma;
while(scanf("%d", &n)!=EOF)
{
if(n==0)
{
break;
}
scanf("%d%*c", &m );
ma.clear();
for(i=0; i<n; i++)
{
scanf("%s", str );
len = strlen(str );
for(j=0; j<len; j++)
{
str[j] = tolower( str[j] );
}
ma[str]++;
}
for(j=0; j<m; j++)
{
scanf("%s", str );
len = strlen(str);
for(i=0; i<len; i++)
{
str[i]=tolower(str[i]);
}
if(ma[str]>=1)
{n--;
ma[str]=0;
}
}
printf("%d\n", n );
}
return 0;
}
方法二:
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
#include <ctype.h>
using namespace std;
int main()
{
char str[30];
int len;
int n, m;
int i, j;
// map<string,int>ma;
while(scanf("%d", &n)!=EOF)
{
if(n==0)
{
break;
}
scanf("%d%*c", &m );
map<string,int>ma;
for(i=0; i<n; i++)
{
scanf("%s", str );
len = strlen(str );
for(j=0; j<len; j++)
{
str[j] = tolower( str[j] );
}
ma[str]++;
}
for(j=0; j<m; j++)
{
scanf("%s", str );
len = strlen(str);
for(i=0; i<len; i++)
{
str[i]=tolower(str[i]);
}
ma.erase(str);
}
printf("%d\n", ma.size() );
}
return 0;
}
STL 之map解决 Message Flood(原字典树问题),布布扣,bubuko.com
STL 之map解决 Message Flood(原字典树问题)
标签:des style blog color strong io for 问题
原文地址:http://www.cnblogs.com/yspworld/p/3890818.html