Document directory
- Problem Source: zsuacm team member
1194. Message flood
| Total: |
23747 |
Accepted: |
4451 |
Rating: |
3.1/5.0 (78 votes) |
Description
Well, how do you feel about mobile phone? Your answer wowould probably be something like that "it's so convenient and benefits people a lot ". however, if you ask Merlin this question on the New Year's Eve, he will definitely answer "What a trouble! I have to keep my fingers moving on the phone the whole night, because I have so far too greeting messages to send! ". Yes, Merlin has such a long name list of his friends, and he wowould like to send a greeting message to each of them. what's worse, Merlin has another long name list of senders that have sent message to him, and he doesn' t want to send another message to bother them (Merlin is so polite that he always replies each message he has es immediately ). so, before he begins to send messages, he needs to figure to how many friends are left to be sent. please write a program to help him.
Here is something that you shoshould note. first, Merlin's friend list is not ordered, and each name is alphabetic strings and case insensitive. these names are guaranteed to be not duplicated. second, some Senders may send more than one message to Merlin, therefore the sender list may be duplicated. third, Merlin is known by so many people, that's why some message senders are even not supported in his friend list.
Input
There are multiple test cases. in each case, at the first line there are two numbers N and M (1 <= n, m <= 20000 ), which is the number of friends and the number of messages he has encoded ed. and then there are n lines of alphabetic strings (the length of each will be less than 10), indicating the names of Merlin's friends, one per line. after that there are m lines of alphabetic strings, which are the names of message senders.
The input is terminated by n = 0.
Output
For each case, print one integer in one line which indicates the number of left friends he must send.
Sample input copy sample input to clipboard
5 3InkfishHenryCarpMaxJerichoCarpMaxCarp0
Sample output
3
Problem Source: zsuacm team member
Key:
Set container
Note:
1. Enter 0 to end the input, which is prone to errors.
At this time, you cannot simply use
While (CIN> N> m)
{...}
The output result is incorrect.
Used here
While (true)
{
If (CIN> N)
Break;
Cin> m;
....
}
2. At the end of each example, remember to clear the container; otherwise, the last result is retained in the container.
3. String case-sensitive conversion. Note that this question is case-insensitive.
How to convert a string to uppercase or lowercase? This is a common task for string matching. However, the standard library of C ++ does not provide the function of converting STD: string to uppercase or lowercase, only when char is converted to toupper and tolower. However, we can use STL transform with toupper/tolower to complete the STD: String Conversion (small) Write function. We also see the power of template programming, a transform function, it can be applied to any type, and any transform action can be completed as long as a function is provided by itself.
C ++
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
int main() {
string s = "Clare";
// toUpper
transform(s.begin(), s.end(), s.begin(), ::toupper);
// toLower
//transform(s.begin(),s.end(),s.begin(), ::tolower);
cout << s << endl;
}
C
#include <stdio.h>
#include <ctype.h>
int main() {
char s[] = "Clare";
int i = -1;
while(s[i++])
s[i] = toupper(s[i]);
// s[i] = tolower(s[i]);
puts(s);
}
Or use the original method to perform a loop for each input string:
String rname = "Alexander ";
For (j = 0; j <rname. Length (); j ++)
Rname [J] = tolower (rname [J]);
My answer:
View code
#include<iostream>
#include<fstream>
#include<set>
#include <cctype>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
int n=0,m=0;
string strFriend,sender;
set<string> friends;
// ifstream cin("input.txt");
set<string>::iterator it;
while(true)
{
if(cin>>n)
break;
cin>>m;
for(int i=0;i<n;++i)
{
cin>>strFriend;
transform(strFriend.begin(), strFriend.end(), strFriend.begin(), ::toupper);
friends.insert(strFriend);
}
for(int j=0;j<m;++j)
{
cin>>sender;
transform(sender.begin(), sender.end(), sender.begin(), ::toupper);
it=friends.find(sender);
if(it!=friends.end())
{
friends.erase(it);
}
}
cout<<friends.size()<<endl;
friends.clear();
}
return 0;
}
Time: