fork download
  1. #include<unordered_map>
  2. void pairSum(int input[], int size, int x) {
  3. /* Don't write main().
  4.   * Don't read input, it is passed as function argument.
  5.   * Print the output and don't return it.
  6.   * Taking input is handled automatically.
  7.   */
  8. unordered_map<int,int>m;
  9. for(int i=0;i<size;i++){
  10.  
  11. int rem = x-input[i];
  12. if(m.find(rem)!=m.end()){
  13. int count = m[rem];
  14. for(int j = 0; j<count; j++){
  15. if(rem<input[i]){
  16. cout<<rem<<" "<<input[i]<<endl;
  17. }
  18. else{
  19. cout<<input[i]<<" "<<rem<<endl;
  20. }
  21. }
  22. }
  23. m[input[i]]++;
  24. }
  25. cout<<endl;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void pairSum(int*, int, int)’:
prog.cpp:8:2: error: ‘unordered_map’ was not declared in this scope
  unordered_map<int,int>m;
  ^~~~~~~~~~~~~
prog.cpp:8:2: note: suggested alternative:
In file included from /usr/include/c++/8/unordered_map:47,
                 from prog.cpp:1:
/usr/include/c++/8/bits/unordered_map.h:102:11: note:   ‘std::unordered_map’
     class unordered_map
           ^~~~~~~~~~~~~
prog.cpp:8:16: error: expected primary-expression before ‘int’
  unordered_map<int,int>m;
                ^~~
prog.cpp:12:12: error: ‘m’ was not declared in this scope
         if(m.find(rem)!=m.end()){
            ^
prog.cpp:16:21: error: ‘cout’ was not declared in this scope
                     cout<<rem<<" "<<input[i]<<endl;
                     ^~~~
prog.cpp:16:21: note: suggested alternative: ‘count’
                     cout<<rem<<" "<<input[i]<<endl;
                     ^~~~
                     count
prog.cpp:16:47: error: ‘endl’ was not declared in this scope
                     cout<<rem<<" "<<input[i]<<endl;
                                               ^~~~
prog.cpp:16:47: note: suggested alternative: ‘enum’
                     cout<<rem<<" "<<input[i]<<endl;
                                               ^~~~
                                               enum
prog.cpp:19:21: error: ‘cout’ was not declared in this scope
                     cout<<input[i]<<" "<<rem<<endl;
                     ^~~~
prog.cpp:19:21: note: suggested alternative: ‘count’
                     cout<<input[i]<<" "<<rem<<endl;
                     ^~~~
                     count
prog.cpp:19:47: error: ‘endl’ was not declared in this scope
                     cout<<input[i]<<" "<<rem<<endl;
                                               ^~~~
prog.cpp:19:47: note: suggested alternative: ‘enum’
                     cout<<input[i]<<" "<<rem<<endl;
                                               ^~~~
                                               enum
prog.cpp:23:9: error: ‘m’ was not declared in this scope
         m[input[i]]++;
         ^
prog.cpp:25:5: error: ‘cout’ was not declared in this scope
     cout<<endl;
     ^~~~
prog.cpp:25:11: error: ‘endl’ was not declared in this scope
     cout<<endl;
           ^~~~
prog.cpp:25:11: note: suggested alternative: ‘enum’
     cout<<endl;
           ^~~~
           enum
stdout
Standard output is empty