产生冠军
有一群人,打乒乓球较量,两两捉对撕杀,每两个人之间最多打一场较量。
球赛的规定如下:
如果A战胜了B,B又战胜了C,而A与C之间没有进行过较量,那么就认定,A肯定能战胜C。
如果A战胜了B,B又战胜了C,而且,C又战胜了A,那么A、B、C三者都不可能成为冠军。
依据这个规定,无需循环较量,或者就能确定冠军。你的工作就是面对一群较量选手,在通过了若干场撕杀之后,确定是否曾经实际上产生了冠军。
Input
输出含有一些选手群,每群选手都以一个整数n(n<1000)结尾,后跟n对选手的比赛结果,比赛结果以一对选手名字(中距离一空格)示意,前者战败后者。如果n为0,则示意输出完结。
Output
对于每个选手群,若你判断出产生了冠军,则在一行中输入“Yes”,否则在一行中输入“No”。
Sample Input
3
Alice Bob
Smith John
Alice Smith
5
a c
c d
d e
b e
a d
0
Sample Output
Yes
No
#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<cstdio>#include<queue>#include<stack> #include<set> using namespace std;//#include<bits/stdc++.h>//万能头文件 //字符翻转 int main(){ int t = 0; while(cin >> t){ if(t == 0){ break; } getchar(); string s1,s2; set<string>str1,str2; while(t--){ cin >> s1 >> s2; str1.insert(s1); str1.insert(s2); str2.insert(s2); } if(str1.size() - str2.size() == 1){ cout << "Yes" << endl; }else{ cout << "No" << endl; } } return 0;}
人见人爱A-B
加入过上个月月赛的同学肯定还记得其中的一个最简略的题目,就是{A}+{B},那个题目求的是两个汇合的并集,明天咱们这个A-B求的是两个汇合的差,就是做汇合的减法运算。(当然,大家都晓得汇合的定义,就是同一个汇合中不会有两个雷同的元素,这里还是揭示大家一下)
呵呵,很简略吧?
Input
每组输出数据占1行,每行数据的开始是2个整数n(0<=n<=100)和m(0<=m<=100),别离示意汇合A和汇合B的元素个数,而后紧跟着n+m个元素,后面n个元素属于汇合A,其余的属于汇合B. 每个元素为不超出int范畴的整数,元素之间有一个空格隔开.
如果n=0并且m=0示意输出的完结,不做解决。
Output
针对每组数据输入一行数据,示意A-B的后果,如果后果为空集合,则输入“NULL”,否则从小到大输入后果,为了简化问题,每个元素前面跟一个空格.
Sample Input
3 3 1 2 3 1 4 7
3 7 2 5 8 2 3 4 5 6 7 8
0 0
Sample Output
2 3
NULL
#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<cstdio>#include<queue>#include<stack> #include<set> using namespace std;//#include<bits/stdc++.h>//万能头文件 //字符翻转 int main(){ int a = 0, b = 0; while(cin >> a >> b){ if(a == 0 && b == 0){ break; } set<int >s; int n = 0; for(int i = 0; i < a; i++){ cin >> n; s.insert(n); } for(int i = 0; i < b; i++){ cin >> n; if(s.find(n) != s.end()){ s.erase(n); } } if(s.size() == 0){ cout << "NULL" << endl; }else{ set<int >::iterator it; for(it = s.begin(); it != s.end(); it++){ cout << *it << " "; } cout << endl; } } return 0;}
Shopping
Every girl likes shopping,so does dandelion.Now she finds the shop is increasing the price every day because the Spring Festival is coming .She is fond of a shop which is called "memory". Now she wants to know the rank of this shop's price after the change of everyday.
Input
One line contians a number n ( n<=10000),stands for the number of shops.
Then n lines ,each line contains a string (the length is short than 31 and only contains lowercase letters and capital letters.)stands for the name of the shop.
Then a line contians a number m (1<=m<=50),stands for the days .
Then m parts , every parts contians n lines , each line contians a number s and a string p ,stands for this day ,the shop p 's price has increased s.
Output
Contains m lines ,In the ith line print a number of the shop "memory" 's rank after the ith day. We define the rank as :If there are t shops' price is higher than the "memory" , than its rank is t+1.
Sample Input
3
memory
kfc
wind
2
49 memory
49 kfc
48 wind
80 kfc
85 wind
83 memory
Sample Output
1
2
#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<cstdio>#include<queue>#include<stack> #include<set> #include<map>using namespace std;//#include<bits/stdc++.h>//万能头文件 int main(){ int t = 0; while(cin >> t){ string s; for(int i = 0; i < t; i ++){ cin >> s; } int m = 0; cin >> m; map<string,int> shop; int num = 0; string p; while(m--){ for(int i = 0; i < t; i++){ cin >> num >> p;//留神题目输出程序 shop[p] += num; } int ans = 1; map<string,int>:: iterator it; for(it = shop.begin(); it != shop.end(); it++){ if(it->second > shop["memory"]){//map<first,second>,map是key_value成对呈现的容器第一个地位肯定是key,并且必须shop[key],[]外面必须是key ans++; } } cout << ans << endl; } } return 0;}