fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <set>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. int main() {
  9. int n;
  10. cin >> n;
  11. map <string, set <string>> engLat, latEng;
  12. while (n--) {
  13. string eng, lat, word;
  14. cin >> eng;
  15. getline(cin, lat);
  16. lat += ",";
  17. for (int i = 3; i < lat.length(); i++) {
  18. if (isalpha(lat[i])) word += lat[i];
  19. else {
  20. engLat[eng].insert(word);
  21. word.clear();
  22. i++;
  23. }
  24. }
  25. }
  26.  
  27. for (auto x : engLat) {
  28. for (auto y : x.first) {
  29. latEng[y] = x.first;
  30. }
  31. }
  32.  
  33. cout << latEng.size() << endl;
  34.  
  35. for (auto x : latEng) {
  36. cout << x.first << " - ";
  37. int count = 1;
  38. for (auto y : x.first) {
  39. if (count < x.second.size()) {
  40. cout << ", ";
  41. count++;
  42. }
  43. cout << y;
  44. }
  45. cout << endl;
  46. }
  47. return 0;
  48. }
Compilation error #stdin compilation error #stdout 0s 4420KB
stdin
3
apple - malum, pomum, popula
fruit - baca, bacca, popum
punishment - malum, multa
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29:19: error: no match for ‘operator[]’ (operand types are ‘std::map<std::__cxx11::basic_string<char>, std::set<std::__cxx11::basic_string<char> > >’ and ‘char’)
             latEng[y] = x.first;
                   ^
In file included from /usr/include/c++/8/map:61,
                 from prog.cpp:2:
/usr/include/c++/8/bits/stl_map.h:490:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::__cxx11::basic_string<char>; _Tp = std::set<std::__cxx11::basic_string<char> >; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, std::set<std::__cxx11::basic_string<char> > > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::set<std::__cxx11::basic_string<char> >; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::__cxx11::basic_string<char>]’
       operator[](const key_type& __k)
       ^~~~~~~~
/usr/include/c++/8/bits/stl_map.h:490:7: note:   no known conversion for argument 1 from ‘char’ to ‘const key_type&’ {aka ‘const std::__cxx11::basic_string<char>&’}
/usr/include/c++/8/bits/stl_map.h:510:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Tp = std::set<std::__cxx11::basic_string<char> >; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, std::set<std::__cxx11::basic_string<char> > > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::set<std::__cxx11::basic_string<char> >; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::__cxx11::basic_string<char>]’
       operator[](key_type&& __k)
       ^~~~~~~~
/usr/include/c++/8/bits/stl_map.h:510:7: note:   no known conversion for argument 1 from ‘char’ to ‘std::map<std::__cxx11::basic_string<char>, std::set<std::__cxx11::basic_string<char> > >::key_type&&’ {aka ‘std::__cxx11::basic_string<char>&&’}
stdout
Standard output is empty