제출 #1143745

#제출 시각아이디문제언어결과실행 시간메모리
1143745Rainmaker2627세 명의 친구들 (BOI14_friends)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; int n; string s; bool ok(string a, string b) { int j=0, v=0; for (int i = 0; i < a.size(); i++) { if (a[i]!=b[j] && v==0) { v++; i--; } else if (a[i] != b[j]) return false; j++; } return true; } int main() { cin.tie(0)->sync_with_stdio(false); cin >> n >> s; if (n%2 == 0) { cout << "NOT POSSIBLE\n"; return 0; } set<string> ans; string a1 = s.substr(0, n/2), b1 = s.substr(n/2); string a2 = s.substr(n/2+1), b2 = s.substr(0, n/2+1); if (ok(a1, b1)) ans.insert(a1); if (ok(a2, b2)) ans.insert(a2); if (ans.size() == 0) cout << "NOT POSSIBLE\n"; else if (ans.size() > 1) cout << "NOT UNIQUE\n"; else cout << ans[0] << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'int main()':
friends.cpp:28:21: error: no match for 'operator[]' (operand types are 'std::set<std::__cxx11::basic_string<char> >' and 'int')
   28 |     else cout << ans[0] << '\n';
      |                     ^