제출 #3727

#제출 시각아이디문제언어결과실행 시간메모리
3727tncks0121Make superpalindrome! (kriii1_M)C++98
0 / 1
4 ms2216 KiB
#include<string> #include<iostream> #include<algorithm> using namespace std; //s보다 사전순 같거나 앞에 있으면서 슈퍼팰린드롬 string make(string s){ //1인 경우는 볼 필요 없다. if(s.length() == 1) return s; int len = s.length(); bool sw = false; for(int i=0; i< (len+1)/2;i++){ char &l = s[i]; char &r = s[len - i - 1]; if( l < r ) sw = true; r = l; } if(sw){ for(int i= (len+1)/2 -1; i>=0; i--){ char &l = s[i]; char &r = s[len - i - 1]; if( l != 'z'){ l++; r= l; break; } l = r = 'a'; } } string ans = make(s.substr(0,len/2)); string ar = ans; reverse(ar.begin(),ar.end()); if(len&1){ if(ans > s.substr(0,len/2)) s[(len)/2] = 'a'; return ans + s[(len)/2] + ar; } return ans + ar; } int main(){ string s; cin >> s ; for(int i=s.length()-1;i>=0;i--){ if(s[i] !='z'){ s[i] ++; break; } s[i] = 'a'; } cout << make(s) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...