제출 #996277

#제출 시각아이디문제언어결과실행 시간메모리
996277SuPythony세 명의 친구들 (BOI14_friends)C++17
100 / 100
39 ms11068 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n; cin>>n;
    string s; cin>>s;
    if (n%2==0) cout<<"NOT POSSIBLE";
    else {
        string l=s.substr(0,(n-1)/2), r=s.substr((n-1)/2+1,(n-1)/2);
        string lc=s.substr((n-1)/2,(n-1)/2+1), rc=s.substr(0,(n-1)/2+1);
        vector<string> ans;
        int ind=0;
        bool wrong=false;
        bool pos=true;
        for (char i: lc) {
            if (i!=l[ind]) {
                if (!wrong) {
                    wrong=true;
                    continue;
                } else {
                    pos=false;
                    break;
                }
            }
            ind++;
            if (ind==lc.size()) break;
        }
        if (pos) ans.push_back(l);
        ind=0;
        wrong=false;
        pos=true;
        for (char i: rc) {
            if (i!=r[ind]) {
                if (!wrong) {
                    wrong=true;
                    continue;
                } else {
                    pos=false;
                    break;
                }
            }
            ind++;
            if (ind==rc.size()) break;
        }
        if (pos) ans.push_back(r);
        if (ans.empty()) cout<<"NOT POSSIBLE";
        else if (ans.size()>1&&ans[0]!=ans[1]) cout<<"NOT UNIQUE";
        else cout<<ans[0];
    }
    return 0;
}

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

friends.cpp: In function 'int main()':
friends.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (ind==lc.size()) break;
      |                 ~~~^~~~~~~~~~~
friends.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             if (ind==rc.size()) break;
      |                 ~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...