1. 程式人生 > 實用技巧 >2018北京區域賽 Palindromes (打表)

2018北京區域賽 Palindromes (打表)

數字太大,找找規律比較好。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const int mod=1e9+7;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int len=(int)s.size();
        if((int
)s.size()==1||s=="11"||s=="10"){ if(s=="11"){ cout<<11<<endl; } else if(s=="10"){ cout<<9<<endl; } else{ cout<<s[0]-'0'-1<<endl; } }
else{ if(s[0]=='1'){ if(s[1]=='0'){ s[1]='9'; string tmp=s.substr(1,len-1); string t=tmp.substr(0,len-2); reverse(t.begin(),t.end()); tmp+=t; cout<<tmp<<endl; }
else{ string tmp=s.substr(1,len-1); string t=tmp; reverse(t.begin(),t.end()); tmp+=t; cout<<tmp<<endl; } } else{ s[0]-=1; string t=s.substr(0,len-1); reverse(t.begin(),t.end()); s+=t; cout<<s<<endl; } } } return 0; }
View Code