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
没有人不辛苦,只有人不喊疼
原文地址:https://www.cnblogs.com/ctyakwf/p/13538019.html