fork(1) download
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20.  
  21.  
  22. // defines
  23. #define KhaledAshraf ios_base::sync_with_stdio(0);cin.tie(0);
  24. #define modulo 1000000007
  25. #define pi 3.1415926535897932384
  26.  
  27. typedef long long int lln;
  28.  
  29.  
  30.  
  31.  
  32. //to be able to use to_string patch::to_string("char or string")
  33.  
  34. namespace patch
  35. {
  36. template < typename T > std::string to_string( const T& n )
  37. {
  38. std::ostringstream stm ;
  39. stm << n ;
  40. return stm.str() ;
  41. }
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. using namespace std;
  53.  
  54. /*******************************************/
  55.  
  56. /*
  57.   ya mas2la zebala accept b2a
  58.  
  59.   O_O
  60.  
  61.   $$$$$$$$$$$$$$$
  62.   $ $ $$$$$$$$$$$$$$$$$$$$$ $ $
  63.   $ $ $ $$$$$$$$$$$$$$$$$$$$$$$$ $ $ $
  64.   $ $ $ $ $$$$$$ $$$$$$ $$$$$$ $ $ $ $
  65.   $$$$$ $$$$$$ $$$$ $$$$$$$ $$$$$
  66.   $$$$$$$$ $$$$$$$ $$$$ $$$$$$$$ $$$$$$$$
  67.   $$$ $$$$$$$$$ $$$$$$ $$$$$$$$$$ $$$
  68.   $$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$
  69.   $ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ $
  70.   $$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$
  71.   $$$ $$$$$$$$$$$$$$$$$$$$$$$$ $$$
  72.   $$$ $$$$$$$$$$$$$$$$ $$
  73.   $$ $$$$$$$$$$ $$
  74.   $$$ $
  75.   $$ $$$$$$$$$$$ $
  76.   $$$ $$$$$$$$$$$ $
  77.   $$$ $$$$$$$$$$
  78.   $$$$$ $$$$$$$$$
  79.   $$$$$$$
  80.   $$$$
  81.  
  82.   Khaled Ashraf
  83. */
  84.  
  85.  
  86. bool check[1000000];
  87. vector <lln> primes;
  88.  
  89. void gen_primes(lln N){
  90.  
  91. for(lln i=2;i<=N;i++){
  92. if(!check[i]){
  93. primes.push_back(i);
  94. for(lln j=i*i;j<=N;j+=i){
  95. check[j]=true;
  96. }
  97. }
  98. }
  99. }
  100.  
  101. lln lcm (lln X , lln Y){
  102. return ( (X*Y)/__gcd(X,Y) );
  103. }
  104.  
  105. long long FastPower(long long B , long long P)
  106. {
  107. if(P==1){return B;}
  108. else if(P%2)return B*FastPower(B*B,P/2);
  109. else return FastPower(B*B,P/2);
  110. }
  111. lln GCD(lln X,lln Y){
  112. if(X>Y){swap(X,Y);}
  113.  
  114. if(Y%X==0){return X;}
  115. GCD(Y,Y%X);
  116. }
  117. bool proj(string S){
  118. for(int i=0;i<S.size();i++){
  119. if(S[i]>='a' && S[i]<='z'){
  120. return false;
  121. }
  122. }
  123. return true;
  124. }
  125.  
  126. bool cmp(pair <int,string> A , pair<int,string> B){
  127. if(A.first>B.first){
  128. return 1;
  129. }
  130. else if(A.first<=B.first){
  131. return 0;
  132. }
  133. }
  134.  
  135. int main()
  136. {
  137. KhaledAshraf;
  138. bool flag=false;
  139. string S;
  140. while(getline(cin,S) && S[0]!='0'){
  141. map <string,string>StudentsProject;
  142. map <string,string>::iterator SPit;
  143. map <string,int>cnt;
  144. map <string,int>::iterator CNit;
  145.  
  146. string LastP="";
  147. while(S[0]!='1'){
  148. if(proj(S)==true){
  149. LastP=S;
  150. cnt[S]=0;
  151. }
  152. else{
  153. if(StudentsProject[S]==LastP || StudentsProject[S]==""){
  154. StudentsProject[S]=LastP;
  155. }
  156. else{
  157. StudentsProject[S]=".";
  158. }
  159. }
  160. getline(cin,S);
  161. }
  162. for(SPit=StudentsProject.begin() ; SPit!=StudentsProject.end() ;SPit++){
  163. if(SPit->second !="."){
  164. cnt[SPit->second]++;
  165. }
  166. }
  167. vector <pair <int,string> >V;
  168.  
  169. for(CNit=cnt.begin() ; CNit!=cnt.end() ; CNit++){
  170. V.push_back({(CNit->second),(CNit->first)});
  171. }
  172. sort(V.begin(),V.end(),cmp);
  173. for(int i=0;i<V.size();i++){
  174. cout<<V[i].second<<" "<<V[i].first<<endl;
  175. }
  176.  
  177. }
  178.  
  179.  
  180.  
  181. return 0;
  182. }
  183.  
  184.  
Success #stdin #stdout 0s 4444KB
stdin
Standard input is empty
stdout
Standard output is empty