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 个)它的前一个字 ...
随机推荐
- <<Python基础教程>>学习笔记 | 第11章 | 文件和素材
打开文件 open(name[mode[,buffing]) name: 是强制选项,模式和缓冲是可选的 #假设文件不在.会报以下错误: >>> f = open(r'D:\text ...
- js的常见函数
var n=0.0145; n.toFixed(2);//保留两位小数 n.lastIndexOf('a');//检索字符串最后出现的位置 n.indexof("h");//检索字 ...
- c#, extract number from string
using System.Text.RegularExpressions; string numberStr = Regex.Match (str, "[0-9]").Value; ...
- unity, unlit surface shader (texColor only surface shader)
要实现双面透明无光照只有纹理色的surface shader. 错误的写法:(导致带有曝光) Shader "Custom/doubleFaceTranspTexColor" { ...
- 并且需要用websocket实时接收数据 VS 组件ng2websocket的
chart.service.ts: import { Injectable } from '@angular/core'; import { WebSocketService } from './we ...
- 面试、笔试中常用的SQL语句(数据库知识必杀)一共50个!!!
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 ...
- hdu 1711 Number Sequence KMP 基础题
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- DDR 复位
将FPGA代码和实际的数字电路对应起来. always @ (negedge clk_ref_200) begin if(ddr3_init_done) 'b10) 'b10 ...
- [JNA系列]Java调用Delphi编写的Dll之实例Delphi使用PWideChar
Delphi代码 unit UnitDll; interface uses StrUtils, SysUtils, Dialogs; function DoBusinessWide(pvData: P ...
- Oracle之配置客户端登陆多个远程数据库
一.引言 一直搞不明白Oracle数据库的客户端是怎么回事,怎么配置,前几天由于工作中需要用到Oracle,而且需要连接两个不同的数据库,就通过上网和请教同事终于把客户端的配置搞定了,记录之,学习之 ...