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. JS正则表达式(转载)

    在JavaScript中,RegExp对象表示正则表达式,用来对字符串进行匹配. 一.两种定义方法: 1.直接量法: /pattern/attribute 2.对象法: new RegExp(patt ...

  2. 安卓端OCR文字识别之番外篇

    拍照识别------OCR怎样在移动端大放异彩 大家好.我是文通晓伟.非常高兴能和大家共同探讨一下OCR识别技术在安卓端的应用. 首先坦白交代,我不是技术流,我是销售狗. 每天有打不完的电话和做不完的 ...

  3. oblique perspective projection

    参考: https://en.wikibooks.org/wiki/GLSL_Programming/Vertex_Transformations <3D游戏与计算机图形学中的数学方法>E ...

  4. EularProject 32: 数字1-9排列构成乘法等式

    Pandigital products Problem 32 We shall say that an n-digit number is pandigital if it makes use of ...

  5. Atitit.png 图片不能显示 php环境下

    Atitit.png 图片不能显示 php环境下 1.1. 不能显示png 下载png 检查使用bcompare与正常png对比.. 多了bom头 , "\xEF\xBB\xBF" ...

  6. flink on yarn 用户代码获取keytab本地文件和principal的方法

    flink on yarn的情况下配置的keytab文件会根据每次yarn application 分配taskmanager的变化都是不一样的,在部分场景下用户代码也需要获得keytab文件在yar ...

  7. 171. Anagrams【medium】

    Given an array of strings, return all groups of strings that are anagrams. Notice All inputs will be ...

  8. 在Windows7和Ubuntu上编译安装MICO

    MICO是CORBA标准的一个实现.开源并且被广泛使用. 首先的首先,看用户手册,在页面"http://www.mico.org/docu.html"找到一本教材"MIC ...

  9. 使用response.setHeader("Content-Disposition","attachment;filename="+fName)下载文件,中文文件名无法显示的问题

    今天遇到这么一个情况,在Action代码中进行文件下载: ActionForm得到file_id,通过file_id进行数据库查询得到file_name以及服务器硬盘上的file_uri,其中file ...

  10. hdu1025 最大上升字串

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...