The successor to a string can be calculated by applying the following rules:
There are multiple test cases. The first line of input is an integer T ≈ 10000 indicating the number of test cases.
Each test case contains a nonempty string s and an integer 1 ≤ n ≤ 100. The string s consists of no more than 100 characters whose ASCII values range from 33(‘!‘) to 122(‘z‘).
For each test case, output the next n successors to the given string s in separate lines. Output a blank line after each test case.
4 :-( 1 cirno=8 2 X 3 /**********/ 4
:-) cirno=9 cirnp=0 Y Z AA /**********0 /**********1 /**********2 /**********3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <string>
#include <stack>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <map>
using namespace std;
#define MAXM 1000000
#define MAXN 110
map<string ,int> my;
int is(char ch)
{
if(ch>='0'&&ch<='9')
return 1;
if(ch>='a'&&ch<='z')
return 2;
if(ch>='A'&&ch<='Z')
return 3;
return 0;
}
int upup(char &ch,int type)
{
if(type==1)
{
if(ch=='9')
{
ch='0';
return 1;//jin
}
else
{
ch++;
return 0;
}
}
if(type==2)
{
if(ch=='z')
{
ch='a';
return 1;//jin
}
else
{
ch++;
return 0;
}
}
if(type==3)
{
if(ch=='Z')
{
ch='A';
return 1;//jin
}
else
{
ch++;
return 0;
}
}
return 0;
}
void update(string &str)
{
int i;
int flag=0;
int jin=0;
int id;
int type;
for(i=str.size()-1;i>=0;i--)
{
if(is(str[i]))
{
jin=upup(str[i],is(str[i]));
flag=1;//you jia guo
type=is(str[i]);
id=i;
if(jin==0)
break;
}
}
if(flag==0)//从来没有 数字 字母
{
str[str.size()-1]++;
}
else if(jin==1)
{
if(type==1)
str.insert(id,"1");//insert(id,'1');
else if(type==2)
str.insert(id,"a");
else if(type==3)
str.insert(id,"A");
}
cout<<str<<endl;
}
int main()
{
int t;
cin>>t;
double num[10];
while(t--)
{
string str;
int n;
cin>>str;
cin>>n;
while(n--)
{
update(str);
}
printf("\n");
}
return 0;
}zoj 3490 String Successor 字符串 进制
原文:http://blog.csdn.net/u013532224/article/details/45115459