fork(3) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. int t;
  7. cin>>t;
  8. int u=1;
  9. while(t--)
  10. {
  11. int n,k,maxm=0;
  12. cin>>n>>k;
  13. cout<<"Case "<<u++<<":"<<endl;
  14. unordered_map<string ,int> m;
  15. queue<string> q;
  16. unordered_set<string> st;
  17. string s,l,p;
  18. for(int i=0;i<n;i++)
  19. {
  20. cin>>s;
  21. if(q.size()<k)
  22. q.push(s);
  23. else
  24. {
  25. p=q.front();
  26. q.pop();
  27. m[p]--;
  28. q.push(s);
  29. st.erase(p);
  30. if(l==p)
  31. maxm=m[p];
  32. }
  33. m[s]++;
  34. st.insert(s);
  35. if(m[s]>=maxm)
  36. {
  37. l=s;
  38. maxm=m[s];
  39. }
  40. if(m[p]>=maxm)
  41. {
  42. maxm=m[p];
  43. l=p;
  44. }
  45. set<string>::iterator it;
  46. for(it=st.begin();it!=st.end();it++)
  47. {
  48. if(m[*it]==maxm)
  49. {
  50. l=*it;
  51. break;
  52. }
  53. }
  54. cout<<l<<" "<<maxm<<endl;
  55. }
  56. }
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0.02s 3484KB
stdin
1
8 3
hello
hi
who
hi
hi
hello
who
when
compilation info
prog.cpp: In function 'int main()':
prog.cpp:14:6: error: 'unordered_map' was not declared in this scope
      unordered_map<string ,int> m;
      ^
prog.cpp:14:27: error: expected primary-expression before ',' token
      unordered_map<string ,int> m;
                           ^
prog.cpp:14:28: error: expected primary-expression before 'int'
      unordered_map<string ,int> m;
                            ^
prog.cpp:16:6: error: 'unordered_set' was not declared in this scope
      unordered_set<string> st;
      ^
prog.cpp:16:26: error: expected primary-expression before '>' token
      unordered_set<string> st;
                          ^
prog.cpp:16:28: error: 'st' was not declared in this scope
      unordered_set<string> st;
                            ^
prog.cpp:27:14: error: 'm' was not declared in this scope
              m[p]--;
              ^
prog.cpp:33:10: error: 'm' was not declared in this scope
          m[s]++;
          ^
stdout
Standard output is empty