이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
string s,ans1,ans2,ans3;
int st,ed;
bool same,ok;
bool cmp(string a, string b) {
if (a.size()==0 || b.size()==0) return true;
for (int i=0; i<a.size(); ++i) {
if (a[i]!=b[i]) return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
cin>>s;
if (s.size()%2==0) {
cout<<"NOT POSSIBLE";
return 0;
}
//consider insert letter in the middle
ok=true;
for (int i=0; i<s.size()/2; ++i) {
if (s[i]!=s[i+s.size()/2+1]) ok=false;
}
if (ok) {
int k=0,idx=0;
while (k<s.size()/2) {
if (s.size()/2!=idx) ans1+=s[idx], ++k;
++idx;
}
}
//consider insert letter on the left string
for (int i=0; i<=s.size()/2; ++i) {
if (s[i]!=s[i+s.size()/2+1] || i==s.size()/2) {
ed=i;
break;
}
}
for (int i=s.size()/2; i>=0; --i) {
if (s[i]!=s[i+s.size()/2] || i==0) {
st=i;
break;
}
}
same=true;
for (int i=st; i<=ed; ++i) {
if (s[i]!=s[st]) {
same=false;
break;
}
}
if (st<ed && !same) {
cout<<"NOT UNIQUE";
return 0;
} else if (st==ed || (same && st<ed)) {
int k=0,idx=0;
while (k<s.size()/2) {
if (st!=idx) ans2+=s[idx], ++k;
++idx;
}
}
//consider insert letter on the right string
for (int i=s.size()/2; i<s.size(); ++i) {
if (s[i]!=s[i-s.size()/2] || i==s.size()-1) {
ed=i;
break;
}
}
for (int i=s.size()-1; i>=s.size()/2; --i) {
if (s[i]!=s[i-s.size()/2-1] || i==s.size()/2) {
st=i;
break;
}
}
same=true;
for (int i=st; i<=ed; ++i) {
if (s[i]!=s[st]) {
same=false;
break;
}
}
if (st<ed && !same) {
cout<<"NOT UNIQUE";
return 0;
} else if (st==ed || (same && st<ed)) {
int k=0,idx=0;
while (k<s.size()/2) {
if (st!=idx) ans3+=s[idx], ++k;
++idx;
}
}
if (!ans1.size() && !ans2.size() && !ans3.size()) cout<<"NOT POSSIBLE";
else if (!cmp(ans1,ans2) || !cmp(ans2,ans3) || !cmp(ans3,ans1)) cout<<"NOT UNIQUE";
else {
if (ans1.size()) cout<<ans1;
else if (ans2.size()) cout<<ans2;
else cout<<ans3;
}
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'bool cmp(std::string, std::string)':
friends.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (int i=0; i<a.size(); ++i) {
| ~^~~~~~~~~
friends.cpp: In function 'int main()':
friends.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=0; i<s.size()/2; ++i) {
| ~^~~~~~~~~~~
friends.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
friends.cpp:35:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if (s.size()/2!=idx) ans1+=s[idx], ++k;
| ~~~~~~~~~~^~~~~
friends.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i=0; i<=s.size()/2; ++i) {
| ~^~~~~~~~~~~~
friends.cpp:42:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if (s[i]!=s[i+s.size()/2+1] || i==s.size()/2) {
| ~^~~~~~~~~~~~
friends.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
friends.cpp:73:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i=s.size()/2; i<s.size(); ++i) {
| ~^~~~~~~~~
friends.cpp:74:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if (s[i]!=s[i-s.size()/2] || i==s.size()-1) {
| ~^~~~~~~~~~~~
friends.cpp:79:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int i=s.size()-1; i>=s.size()/2; --i) {
| ~^~~~~~~~~~~~
friends.cpp:80:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | if (s[i]!=s[i-s.size()/2-1] || i==s.size()/2) {
| ~^~~~~~~~~~~~
friends.cpp:97:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | while (k<s.size()/2) {
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |