string sn,cn; int ans[maxn]; int main(){ int n; cin>>n; cin>>sn; cn = sn; reverse(cn.begin(),cn.end()); for(int i=0;i<sn.size();i++){ int t = sn[i] - 'a'; que[t].push(i); } for(int i=0;i<n;i++){ int t = cn[i] -
In the first example, you have to swap the third and the fourth elements, so the string becomes "aazaa". Then you have to swap the second and the third elements, so the string becomes "azaaa". So, it is possible to reverse the string in two swaps. Since the string in the second ...
nintegersci(0 ≤ ci ≤ 109), thei-th of them is equal to the amount of energy Vasiliy has to spent in order to reverse thei-th string. nlines, each containing a string consisting of lowercase English letters. The total length of these strings doesn't exceed100 000. Output...
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int m[111][111]; const int maxn =1e5 + 10; int id[maxn]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; string s; cin>>s; int cnt=0; int...
Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currentlynota palindrome, and the last operation was not reverse. That is, if Alice reverses the string, then Bob can't reverse in the next move, and vice versa. ...
E. String Reversal time limit per test2 seconds memory limit per test256 megabytes You are given a string ss. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last ...
Codeforces Round #644 (Div. 3)A->H(H为进制+reverse) http://codeforces.com/contest/1360/problem/A 题意: 用最小正方形,容下两个相同矩形。 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std;...
int n; string s[maxnum]; string rev(string ss) { reverse(ss.begin(), ss.end()); return ss; } void slove() { cin >> n; set<string>st; for (int i = 1; i <= n; i++)cin >> s[i]; for (int i = 1; i <= n; i++) { st.insert(s[i]); if (st.count(rev(...
size()-1; while(s[l]==s[r]&&l<r) l++,r--; string t1=s.substr(0,l),t2=s.substr(r+1); s=s.substr(l,r-l+1); t=s; reverse(t.begin(),t.end()); string a=s+'*'+t,b=t+'*'+s; string p=a.substr(0,getnext(a)); string q=b.substr(0,getnext(b)); cout<<...
void solve(){ int n;cin>>n; string s;cin>>s; string rs=s; reverse(rs.begin(),rs.end()); int f=1; for(int i=0;i<s.size();i++){ if(s[i]<rs[i]){ f=1; break; } if(s[i]>rs[i]){ f=0; break; } } if(f){ cout<<s<<'\n'; } else { cout<<rs<<s<<...