zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    Java中OutOfMemoryError(内存溢出)的情况及解决办法
    php strtotime函数服务器和本地不相同
    Object传入String类型和其他
    Java静态变量,常量,成员变量,局部变量
    Vector使用
    Java反射机制
    List和ArrayList,LinkList的区别
    phpstrtotime()对于31日求上个月有问题
    PGsql解决时差24H
    drawable 另外一种形式dimens.xml
  • 原文地址:https://www.cnblogs.com/xuwanghu/p/2983290.html
Copyright © 2011-2022 走看看