产生冠军
有一群人,打乒乓球比赛,两两捉对撕杀,每两个人之间最多打一场比赛。
球赛的规则如下:
如果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;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。