http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4313
挺烦的题。代码太乱自己都看不懂
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string a;
string ff[5];
int n;
bool f[10005];
int judge(char c)
{
if('a'<=c&&c<='z')
return 1;
if('A'<=c&&c<='Z')
return 2;
if('0'<=c&&c<='9')
return 3;
return 4;
}
bool bjudge(char c)
{
if(c=='z'||c=='Z'||c=='9')
return true;
return false;
}
void add(int pos)
{
int t=judge(a[pos]);
if(bjudge(a[pos]))
{
if(t==1)
a[pos]='a';
else if(t==2)
a[pos]='A';
else
a[pos]='0';
int tt=pos;
for(int i=pos-1;i>=0;i--)
{
if(judge(a[i])<=3)
{
tt=i;
break;
}
}
if(tt==pos)
{
a.insert(pos,ff[t]);
}
else
add(tt);
}
else
a[pos]++;
}
int main()
{
int cnt;
ff[1]="a";
ff[2]="A";
ff[3]="1";
cin>>cnt;
while(cnt--)
{
cin>>a>>n;
while(n--)
{
int pos=a.size();
for(int i=a.size()-1;i>=0;i--)
{
if(judge(a[i])<=3)
{
pos=i;
break;
}
}
if(pos==a.size())
a[pos-1]++;
else
add(pos);
cout<<a<<endl;
}
cout<<endl;
}
// system("pause");
return 0;
}