ZOJ-3490-String Successor【8th浙江省赛】【模拟】
来源:互联网 发布:我知天下之中央 编辑:程序博客网 时间:2024/05/01 21:47
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
题目链接:ZOJ-3490
题目大意:
1. 特殊情况:字符串中无字母和数字。此时的操作是,将最右边的非字母数字的字符ASC2码+1
2. 正常情况 : 字符串中含有字母和数字
① 从最右边的字母(数字)++,如果是9或者Z或者z则产生进位。
②如果进位完之后,前面已经没有数字或者字母可以++的,则在最左边的字母(数字)的左侧增加一个’1’或者’A’或者’a’视最左边的字母(数字)类型而定
题目思路:直接模拟.
我的bug样例是 *****7*****
以下是代码:
#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>#include <string>#include <set>#include <functional>#include <numeric>#include <sstream>#include <stack>#include <map>#include <queue>#include<iomanip>using namespace std;int main(){ int t; cin >> t; while(t--) { string s; int k; cin >>s >> k; int pos = -1; for (int i = 0; i < s.size(); i++) { if (isalpha(s[i]) || isdigit(s[i])) { pos = i; break; } } while(k--) { if (pos != -1) { int add = 0; int i; for (i = s.size() - 1; i >= pos; i--) { if(isdigit(s[i])) { if (s[i] == '9') add = 1,s[i] = '0'; else s[i]++,add = 0; if (add == 0) break; } if (isalpha(s[i])) { if (s[i] == 'z') add = 1,s[i] = 'a'; else if (s[i] == 'Z') add = 1,s[i] = 'A'; else s[i]++,add = 0; if (add == 0) break; } } if (add == 1) { if (s[i + 1] >= 'A' && s[i+1] <= 'Z') s.insert(pos,"A"); if (s[i+1] >= '0' && s[i+1] <= '9') s.insert(pos,"1"); if (s[i+1] >= 'a' && s[i+1] <= 'z') s.insert(pos,"a"); } } else { int add = 0; for (int i = s.size()- 1; i >= 0; i--) { s[i]++; if (isalpha(s[i]) || isdigit(s[i])) pos = i; break; } } cout << s << endl; } cout << endl; } return 0;}
- ZOJ-3490-String Successor【8th浙江省赛】【模拟】
- ZOJ 3490String Successor(模拟)
- zoj 3490 String Successor 模拟
- ZOJ- 3490 String Successor 模拟
- ZOJ 3490 String Successor(模拟啊 )
- ZOJ - 3490 String Successor 递归模拟
- ZOJ 3490 String Successor(模拟)
- zoj 3490 string successor
- ZOJ 3490 String Successor
- zoj 3490 String Successor
- ZOJ 3490 String Successor
- ZOJ-3607-Lazier Salesgirl【模拟】【贪心】【9th浙江省赛】
- ZOJ-3879-Capture the Flag【模拟】【12th浙江省赛】
- ZOJ-3326-An Awful Problem【7th浙江省赛】【模拟】
- ZOJ-3327-Friend Number【7th浙江省赛】【模拟】【数学】
- ZOJ-3601-Unrequited Love【9th浙江省赛】【模拟】【STL】
- ZOJ-3705-Applications【模拟】【10th浙江省赛】
- ZOJ Problem Set - 3490 String Successor(字符串模拟)
- android之序列化
- cuda error问题的解答
- 1053. Path of Equal Weight (30)
- 慕课网【HTML+CSS】3.13前学习内容汇总
- java学习之(一) 基本数据及语法
- ZOJ-3490-String Successor【8th浙江省赛】【模拟】
- netty在游戏服务器开发中的应用(一)
- Python开发接水果小游戏
- 使用python实现打印所有100以内的所有质数
- 《leetCode》:Evaluate Reverse Polish Notation
- poj3235 Fence Repair 优先队列 哈弗曼树
- Loadrunner监控win10服务器资源(设置)
- 左值 右值
- Mybatis第三弹