Time Limit: 2 Seconds Memory Limit: 65536 KB

The successor to a string can be calculated by applying the following rules:

Ignore the nonalphanumerics unless there are no alphanumerics, in this case, increase the rightmost character in the string.

The increment starts from the rightmost alphanumeric.

Increase a digit always results in another digit (‘0’ -> ‘1’, ‘1’ -> ‘2’ … ‘9’ -> ‘0’).

Increase a upper case always results in another upper case (‘A’ -> ‘B’, ‘B’ -> ‘C’ … ‘Z’ -> ‘A’).

Increase a lower case always results in another lower case (‘a’ -> ‘b’, ‘b’ -> ‘c’ … ‘z’ -> ‘a’).

If the increment generates a carry, the alphanumeric to the left of it is increased.

Add an additional alphanumeric to the left of the leftmost alphanumeric if necessary, the added alphanumeric is always of the same type with the leftmost alphanumeric (‘1’ for digit, ‘A’ for upper case and ‘a’ for lower case).

Input

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’).

Output

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.

Sample Input

4

:-( 1

cirno=8 2

X 3

/****/ 4

Sample Output

:-)

cirno=9

cirnp=0

Y

Z

AA

/**********0

/**********1

/**********2

/**********3

代码写的太丑了

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
char a[105];
char b[105];
int n;
int len;
int judge(char x)
{
if((x<='9'&&x>='0')||(x<='z'&&x>='a')||(x<='Z'&&x>='A'))
return 1;
return 0;
}
void fun(int &pos)
{
if(a[pos]=='9')
{
int j;
for( j=pos-1;j>=0;j--)
if(judge(a[j])) break;
if(j==-1)
{
len++;
for(int i=len-1;i>=pos+1;i--)
a[i]=a[i-1];
a[pos+1]='0';
a[pos]='1';
}
else
{
a[pos]='0';
fun(j); }
}
else if(a[pos]=='z')
{
int j;
for( j=pos-1;j>=0;j--)
if(judge(a[j])) break;
if(j==-1)
{
len++;
for(int i=len-1;i>=pos+1;i--)
a[i]=a[i-1];
a[pos+1]='a';
a[pos]='a';
}
else
{
a[pos]='a';
fun(j); }
}
else if(a[pos]=='Z')
{
int j;
for( j=pos-1;j>=0;j--)
if(judge(a[j])) break;
if(j==-1)
{
len++;
for(int i=len-1;i>=pos+1;i--)
a[i]=a[i-1];
a[pos+1]='A';
a[pos]='A';
}
else
{
a[pos]='A';
fun(j); }
}
else
{
a[pos]++;
} }
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s%d",a,&n);
len=strlen(a);
int num2=len;
int i;
for( i=len-1;i>=0;i--)
{
if(judge(a[i]))
break;
}
if(i==-1)
{
int num=n;
int pos=len-1;
while(num>=1)
{
fun(pos);
if(len>num2)
{
pos+=len-num2;
num2=len;
} num--;
for(int j=0;j<=len-1;j++)
printf("%c",a[j]);
cout<<endl;
}
cout<<endl; }
else
{
int num=n;
int pos=i;
while(num>=1)
{
fun(pos);
if(len>num2)
{
pos+=len-num2;
num2=len;
}
num--;
for(int j=0;j<=len-1;j++)
printf("%c",a[j]);
cout<<endl;
}
cout<<endl;
}
}
return 0;
}

ZOJ 3490 String Successor(模拟)的更多相关文章

  1. ZOJ 3490 String Successor

    点我看题目 题意 : 给你一个字符串,让你按照给定规则进行处理. 如果字符串里有字母或者是数字就忽略非字符数字,如果没有,就让最右边的那个字符+1. 增量都是从最右边的字母或者数字开始的. 增加一个数 ...

  2. ZOJ 3490 String Successor 字符串处理

    一道模拟题,来模拟进位 暴力的从右往左扫描,按规则求后继就好了.除了Sample已给出的,还有一些需要注意的地方: 9的后继是10,而不是00: (z)的后继是(aa),而不是a(a): 输入虽然最长 ...

  3. String Successor(模拟)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3490 题意:给出一个字符串,一个操作次数,每次操作从当前字符串最右边的字符 ...

  4. ZOJ——String Successor(字符串模拟题目)

    ZOJ Problem Set - 3490 String Successor Time Limit: 2 Seconds      Memory Limit: 65536 KB The succes ...

  5. String Successor zoj 3490

    链接 [https://vjudge.net/contest/294259#problem/D] 题意 就是给你一个字符串,要进行n次操作 让你输出每次的字符串 操作规则: 1.如果有数字或者字母就忽 ...

  6. ZOJ 3790 Consecutive Blocks 模拟题

    problemCode=3790">Consecutive Blocks 先离散一下,然后模拟,把一种颜色i所在的位置都放入G[i]中.然后枚举一下终点位置,滑动窗体使得起点和终点间花 ...

  7. ZOJ 3826 Hierarchical Notation 模拟

    模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...

  8. Codeforces Round #550 (Div. 3) E. Median String (模拟)

    Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. 2018.08.22 NOIP模拟 string(模拟)

    string [描述] 给定两个字符串 s,t,其中 s 只包含小写字母以及*,t 只包含小写字母. 你可以进行任意多次操作,每次选择 s 中的一个*,将它修改为任意多个(可以是 0 个)它的前一个字 ...

随机推荐

  1. sass 的学习

    导入scss @import "../../sass/variables.scss"; @import "../../sass/helper.scss"; @m ...

  2. Asp.net2.0里的SessionPageStatePersister

    备注: ASP.NET 页可在处理和提供任何网页所必需的原本无状态 HTTP 请求与响应之间存储 Page 状态信息.此状态称为“视图状态”. ASP.NET 的默认持久性机制是使用 HiddenFi ...

  3. 微信模板消息php

    微信的模板消息需要认证的公众号后台申请 申请通过后就可以用平台定义的消息模板了 define('IN_ECS', true); require(dirname(__FILE__) . '/includ ...

  4. Xcode 警告信息处理:Format string is not a string literal (potentially insecure)

    转自:http://www.oschina.net/question/54100_33881 NSObject *obj = @"A string or other object." ...

  5. makefile之调试信息

    makefile 调试 1. 添加调试信息 执行到error时会中断,warning不中断makefile的执行, info不打印当前makefile名和行号. a.$(warning "s ...

  6. tensorboard 之 TF可视化

    tensorboard是TF提供的一个可视化的工具 1.tensorboard可视化的数据来源? 将tensorflow程序运行过程中输出的日志文件进行可视化展示. 1.1 tensorflow怎样输 ...

  7. shell script 在if 的判断条件正则表达式=~中引号问题

    今天在脚本里运行if判断的时候,总是进不了对应的分支,检查正则表达式也没有错误.单独拿到shell里面执行还是显示没有匹配.比较奇怪,就搜了下,才发现是在=~ 后面的正则表达式上不能加上引号,而且以点 ...

  8. bootstrap table 服务器端分页--ashx+ajax

    1.准备静态页面 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-T ...

  9. Oracle(2)数据库

    1.使用"||"连接多个字段,合并成一列 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWFudGluZ21laQ==/font/5a ...

  10. 破解idea注册码

    添加 “0.0.0.0 account.jetbrains.com”到host, hosts位置:C:\Windows\System32\drivers\etc 获取注册码网址: http://ide ...