• String Successor


    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <cstdlib>
    using namespace std;

    string str;

    int main()
    {
        int T;
        int num;
        int i,j;
        int mak;
        int flag;
        int k;
        cin>>T;
        while(T--)
     {
          cin>>str>>num;
       for(i=1;i<=num;i++)
       {
        int len=str.size();
        flag=1;
        mak=0;
        k=0;
        for(j=len-1;j>=0&&flag;j--)
        {
         if(str[j]>='0'&&str[j]<='9')
         {
          str[j]+=flag;
          if(str[j]>'9') 
           str[j]='0';
          else
           flag=0;
          mak=1;
          k=j;
         }
                 else if(str[j]>='a'&&str[j]<='z')
        {
         str[j]+=flag;
         if(str[j]>'z')
          str[j]='a';
         else
          flag=0;
         mak=2;
         k=j;
                 }
                 else if(str[j]>='A'&&str[j]<='Z')
        {
         str[j]+=flag;
         if(str[j]>'Z')
          str[j]='A';
         else
          flag=0;
         mak=3;
         k=j;
                 }
        }
              if(flag)
        {
                if(mak==0)
       {
        str[len-1]++;
                }
                else if(mak==1)
       {
                 string::iterator it;
                 it=str.begin();
                 str.insert(it+k,'1');
                }
                else if(mak==2)
       {
        string::iterator it;
        it=str.begin();
        str.insert(it+k,'a');
                }
                else if(mak==3)
       {
        string::iterator it;
        it=str.begin();
        str.insert(it+k,'A');
                }
              }
        cout<<str<<endl;
       }
       cout<<endl;
        }
        return 0;
    }

  • 相关阅读:
    CodeForces
    CodeForces
    Comet OJ
    CodeForces
    2019年第五届计蒜之道复赛总结
    2019计蒜之道初赛4 B. 腾讯益智小游戏—矩形面积交(简单)(矩形交集)
    2019计蒜之道初赛3 D. 阿里巴巴协助征战SARS(困难)(大数取余+欧拉降幂)
    2018计蒜之道复赛 贝壳找房函数最值(贪心+优先队列)
    牛客想开了大赛2 A-【六】平面(切平面)
    2018年第九届蓝桥杯国赛试题(JavaA组)
  • 原文地址:https://www.cnblogs.com/xuwanghu/p/2983290.html
Copyright © 2020-2023  润新知