7-3 find a common elective - hebust
Each student likes different programming languages. Please program to find a programming language that everyone likes.
Input format:
The first line of input is the number of records
The first line is followed by the programming language records of each student. The names and programming languages are separated directly by English colons, and the programming languages are separated by spaces.
Output format:
The output is the programming language that we all like (if the result is empty, then none is output).
Input example:
Here is a set of inputs. For example:
3
gcs:java js php
cxy:js python c++
sds:c++ c js
Output example:
The corresponding output is given here. For example:
js
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <set> #include <stdio.h> #include <algorithm> using namespace std; int main() { set<string> begin_str; set<string> result; int n; int ifhave; scanf("%d",&n); for(int i=0; i<n; i++) { set<string> v_str; string false_str; cin>>false_str; int len = false_str.size(); string true_str = false_str.substr(false_str.find(":")+1,len-1); v_str.insert(true_str); char a; scanf("%c",&a); while(a!='\n') { string temp; cin>>temp; v_str.insert(temp); a = getchar(); } if(i==0) { begin_str = v_str; continue; } set_intersection(begin(begin_str),end(begin_str),begin(v_str),end(v_str),inserter(result,begin(result))); if(result.size()==0) { printf("none"); result.clear(); break; } begin_str = result; if(i!=(n-1)){ result.clear(); } } if(result.size()!=0) { for(set<string>::iterator it=begin_str.begin(); it!=begin_str.end(); it++) { cout<<*it; } } return 0; }