QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460583#8829. AibohphobiaQwertyPi#Compile Error//C++14673b2024-07-01 21:12:162024-07-01 21:12:16

Judging History

你现在查看的是最新测评结果

  • [2024-07-01 21:12:16]
  • 评测
  • [2024-07-01 21:12:16]
  • 提交

answer

#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define sz(a) (int) (a).size();
using namespace std;

void solve() {
    string s; cin >> s;
    map<char, int> M;
    for (auto c : M) {
        M[c]++;
    }

    if (M.size() <= 2) {
        cout << "NO" << '\n';
        return;
    }

    cout << "YES" << '\n';
    for (auto [c, cc] : M) {
        cout << c;
    }
    for (auto [c, cc] : M) {
        for (int  i = 1; i < cc; i++) {
            cout << c;
        }
    }
    cout << '\n';
}

int32_t main(){
    cin.tie(0); cout.tie(0)->sync_with_stdio(false);
    int t; cin >> t;
    while (t--) {
        solve();
    }
}

Details

answer.code: In function ‘void solve()’:
answer.code:10:10: error: no match for ‘operator[]’ (operand types are ‘std::map<char, int>’ and ‘std::pair<const char, int>’)
   10 |         M[c]++;
      |          ^
In file included from /usr/include/c++/13/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:152,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_map.h:504:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = char; _Tp = int; _Compare = std::less<char>; _Alloc = std::allocator<std::pair<const char, int> >; mapped_type = int; key_type = char]’
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from ‘std::pair<const char, int>’ to ‘const std::map<char, int>::key_type&’ {aka ‘const char&’}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_map.h:524:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = char; _Tp = int; _Compare = std::less<char>; _Alloc = std::allocator<std::pair<const char, int> >; mapped_type = int; key_type = char]’
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from ‘std::pair<const char, int>’ to ‘std::map<char, int>::key_type&&’ {aka ‘char&&’}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
answer.code:19:15: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   19 |     for (auto [c, cc] : M) {
      |               ^
answer.code:22:15: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   22 |     for (auto [c, cc] : M) {
      |               ^