UVA10815
注意输出流的用法。
1 #include2 #include <set> 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int main() 9 { 10 string s,s1; 11 char c; 12 set<string> ss; 13 while(getline(cin,s)){ 14 int len = s.length(); 15 for(int i = 0; i < len; i++){ 16 if(isalpha(s[i])) 17 s[i] = tolower(s[i]); 18 else s[i] = ' '; 19 } 20 istringstream sss(s); 21 while(sss>>s1) ss.insert(s1); 22 } 23 set<string>::iterator it = ss.begin(); 24 for(;it != ss.end();++it){ 25 cout << (*it) <<endl; 26 } 27 return 0; 28 }
Misha and Changing Handles
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
Input
The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.
Next q lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.
Output
In the first line output the integer n — the number of users that changed their handles at least once.
In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
Example
5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov
3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123
1 #include2 #include
What Are You Talking About
InputThe problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
OutputIn this problem, you have to output the translation of the history book.
Sample Input
START from fiwo hello difh mars riwosf earth fnnvk like fiiwj END START difh, i'm fiwo riwosf. i fiiwj fnnvk! END
Sample Output
hello, i'm from mars. i like earth!
1 #include2 #include
SPY
A:the list contains that will come to the NationX’s frontier.
B:the list contains spies that will be sent by Nation Y.
C:the list contains spies that were sent to NationY before.
InputThere are several test cases.
Each test case contains four parts, the first part contains 3 positive integers A, B, C, and A is the number which will come into the frontier. B is the number that will be sent by Nation Y, and C is the number that NationX has sent to NationY before.
The second part contains A strings, the name list of that will come into the frontier.
The second part contains B strings, the name list of that are sent by NationY.
The second part contains C strings, the name list of the “dual_spy”.
There will be a blank line after each test case.
There won’t be any repetitive names in a single list, if repetitive names appear in two lists, they mean the same people.
OutputOutput the list that the commander should caught (in the appearance order of the lists B).if no one should be caught, then , you should output “No enemy spy”Sample Input
8 4 3 Zhao Qian Sun Li Zhou Wu Zheng Wang Zhao Qian Sun Li Zhao Zhou Zheng 2 2 2 Zhao Qian Zhao Qian Zhao Qian
Sample Output
Qian Sun Li No enemy spy
1 #include2 using namespace std; 3 4 int main() { 5 ios::sync_with_stdio(false); cin.tie(0); 6 int a, b, c; 7 int w = 0; 8 string name; 9 while (cin >> a >> b >> c) { 10 set<string> s; 11 vector<string> v; 12 for (int i=0; i) { 13 cin >> name; 14 // cout << ++w < 15 s.insert(name); 16 } 17 for (int j=0; j) { 18 cin >> name; 19 // cout << ++w <20 if (s.count(name)) v.push_back(name); 21 } 22 for (int k=0; k 23 cin >> name; 24 // cout << ++w <) { 25 for (int i=0; i 26 if (v[i] == name) { 27 v.erase(v.begin()+i); 28 } 29 } 30 } 31 if (v.empty()) cout << "No enemy spy\n"; 32 else { 33 int sz = v.size(); 34 cout << v[0]; 35 for (int i=1; i) { ) 36 cout << " " << v[i]; 37 cout << "\n"; 38 } 39 } 40 return 0; 41 }
Bombing
It seems not to be a hard work in circumstances of street battles, however, you’ll be encountered a much more difficult instance: recounting exploits of the military. In the bombing action, the commander will dispatch a group of bombers with weapons having the huge destructive power to destroy all the targets in a line. Thanks to the outstanding work of our spy, the positions of all opponents’ bases had been detected and marked on the map, consequently, the bombing plan will be sent to you.
Specifically, the map is expressed as a 2D-plane with some positions of enemy’s bases marked on. The bombers are dispatched orderly and each of them will bomb a vertical or horizontal line on the map. Then your commanded wants you to report that how many bases will be destroyed by each bomber. Notice that a ruined base will not be taken into account when calculating the exploits of later bombers.
InputMultiple test cases and each test cases starts with two non-negative integer N (N<=100,000) and M (M<=100,000) denoting the number of target bases and the number of scheduled bombers respectively. In the following N line, there is a pair of integers x and y separated by single space indicating the coordinate of position of each opponent’s base. The following M lines describe the bombers, each of them contains two integers c and d where c is 0 or 1 and d is an integer with absolute value no more than 10 9, if c = 0, then this bomber will bomb the line x = d, otherwise y = d. The input will end when N = M = 0 and the number of test cases is no more than 50.
OutputFor each test case, output M lines, the ith line contains a single integer denoting the number of bases that were destroyed by the corresponding bomber in the input. Output a blank line after each test case.Sample Input
3 2 1 2 1 3 2 3 0 1 1 3 0 0
Sample Output
2 1
1 #include2 #include
HDU
1 #include2 #include 3 #include <set> 4 #include 5 using namespace std; 6 set<string>mp; 7 int main() 8 { 9 string s, sss; 10 while(getline(cin,s)){ 11 if(s == "#") 12 break; 13 istringstream ss(s); 14 while(ss>>sss){ 15 mp.insert(sss); 16 } 17 cout << mp.size() << endl; 18 mp.clear(); 19 } 20 return 0; 21 }