ZOJ 3490 String Successor(模拟)
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(模拟)的更多相关文章
- ZOJ 3490 String Successor
点我看题目 题意 : 给你一个字符串,让你按照给定规则进行处理. 如果字符串里有字母或者是数字就忽略非字符数字,如果没有,就让最右边的那个字符+1. 增量都是从最右边的字母或者数字开始的. 增加一个数 ...
- ZOJ 3490 String Successor 字符串处理
一道模拟题,来模拟进位 暴力的从右往左扫描,按规则求后继就好了.除了Sample已给出的,还有一些需要注意的地方: 9的后继是10,而不是00: (z)的后继是(aa),而不是a(a): 输入虽然最长 ...
- String Successor(模拟)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3490 题意:给出一个字符串,一个操作次数,每次操作从当前字符串最右边的字符 ...
- ZOJ——String Successor(字符串模拟题目)
ZOJ Problem Set - 3490 String Successor Time Limit: 2 Seconds Memory Limit: 65536 KB The succes ...
- String Successor zoj 3490
链接 [https://vjudge.net/contest/294259#problem/D] 题意 就是给你一个字符串,要进行n次操作 让你输出每次的字符串 操作规则: 1.如果有数字或者字母就忽 ...
- ZOJ 3790 Consecutive Blocks 模拟题
problemCode=3790">Consecutive Blocks 先离散一下,然后模拟,把一种颜色i所在的位置都放入G[i]中.然后枚举一下终点位置,滑动窗体使得起点和终点间花 ...
- ZOJ 3826 Hierarchical Notation 模拟
模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...
- 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 ...
- 2018.08.22 NOIP模拟 string(模拟)
string [描述] 给定两个字符串 s,t,其中 s 只包含小写字母以及*,t 只包含小写字母. 你可以进行任意多次操作,每次选择 s 中的一个*,将它修改为任意多个(可以是 0 个)它的前一个字 ...
随机推荐
- checkbox 全选操作
<html> <head></head> <body> <div id="places"> <input type ...
- Spark-shell 无法启动之网络问题
由于需要首次手动安装sbt,需要联网,故将虚拟机的网络适配器模式设置为"桥接模式",这样就可以和互联网相连接. 但是后面执行"spark-shell --master ...
- Atitit.js获取上传文件全路径
Atitit.js获取上传文件全路径 1. 默认的value只能获取文件名..安全原因.. 1 2. Firefox浏览器的读取 1 3. Html5 的file api 2 4. 解决方法::使用a ...
- [git]git动画教程
git学习资料比较好的有廖雪峰的教程 还有2个动画教程: https://www.zhihu.com/question/38008771 git-scm 廖雪峰-Git教程 git-for ...
- JS高程3:Ajax与Comet-进度事件、跨源资源共享
有以下 6 个进度事件 loadstart:在接收到响应数据的第一个字节时触发. progress:在接收响应期间持续不断地触发. error:在请求发生错误时触发. abort:在因 ...
- 【Objective-C】02-Objective-C学习及iOS开发的准备
前言 由于大部分朋友对iOS开发还是有比较多的疑问,比如是不是一定要买iPhone和苹果笔记本才能做iOS开发?因此,这讲就为广大有意学习iOS开发的朋友们进行解惑. 一.什么是iOS开发 iOS是由 ...
- RTFSC-afinal框架[一]
RTFSC-afinal框架 finalActivity模块 : android中的ioc框架,完全注解方式就可以进行UI绑定和事件绑定.无需findViewById和setClickListen ...
- Jquery学习笔记(11)--jquery的ajax删除用户,非常简单!
jquery的ajax,简直简单!!只要一个$.get(url,map,function)就搞定了! index.php: <!DOCTYPE html> <html lang=&q ...
- Python List 中 Append 和 Extent 方法不返回值。
Append: list的append 方法是没有返回值的,因此list 的引用L被置为空 结果也就自然是空了. 再看一个例子: append 跟extend方法的区别是什么呢? 其实这样看的就很清楚 ...
- zookeeper安装与集群搭建
此处以centos系统下zookeeper安装为例,详细步骤可参考官网文档:zookeeper教程 一.单节点部署 1.下载zookeeper wget http://mirrors.hust.edu ...