zoj 3490 String Successor

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值