zoj3490
2016-04-15 13:33
148 查看
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <queue> #include <string> #include <string.h> #include <map> #include <vector> typedef long long LL ; int isOk(char c){ return '0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' ; } std::string nextSuccessor(std::string word){ int rightMost ; for(rightMost = word.size()-1 ; rightMost >= 0 ; rightMost--){ if(isOk(word[rightMost])) break ; } if(rightMost >= 0){ if(('0'<= word[rightMost] && word[rightMost] < '9') || ('a' <= word[rightMost] && word[rightMost] < 'z') || ('A' <= word[rightMost] && word[rightMost] < 'Z') ) word[rightMost]++ ; else if(word[rightMost] == '9'){ word[rightMost] = '0' ; int fd = 0 ; for(int j = rightMost - 1 ; j >= 0 ; j--){ if(isOk(word[j])) fd = 1 ; } if(! fd){ std::string head = word.substr(0 , rightMost) ; std::string tail = word.substr(rightMost) ; return head + "1" + tail ; } else{ std::string tail = word.substr(rightMost) ; std::string head = word.substr(0 , rightMost) ; return nextSuccessor(head) + tail ; } } else if(word[rightMost] == 'z'){ word[rightMost] = 'a' ; int fd = 0 ; for(int j = rightMost - 1 ; j >= 0 ; j--){ if(isOk(word[j])) fd = 1 ; } if(! fd){ std::string head = word.substr(0 , rightMost) ; std::string tail = word.substr(rightMost) ; return head + "a" + tail ; } else{ std::string tail = word.substr(rightMost) ; std::string head = word.substr(0 , rightMost) ; return nextSuccessor(head) + tail ; } } else if(word[rightMost] == 'Z'){ word[rightMost] = 'A' ; int fd = 0 ; for(int j = rightMost - 1 ; j >= 0 ; j--){ if(isOk(word[j])) fd = 1 ; } if(! fd){ std::string head = word.substr(0 , rightMost) ; std::string tail = word.substr(rightMost) ; return head + "A" + tail ; } else{ std::string tail = word.substr(rightMost) ; std::string head = word.substr(0 , rightMost) ; return nextSuccessor(head) + tail ; } } } else word[word.size()-1]++ ; return word ; } char word[108] ; int main(){ int t , k ; scanf("%d" , &t) ; while(t--){ scanf("%s%d" ,word , &k) ; std::string s = std::string(word) ; for(int i = 1 ; i <= k ; i++){ s = nextSuccessor(s) ; printf("%s\n" , s.c_str()) ; } puts("") ; } return 0; }
相关文章推荐
- chrome浏览器安装
- 第六周作业
- leetcode- Move Zeros
- sql内联查询
- BestCoder Round #72 Clarke and chemistry
- URLDecoder: Incomplete trailing escape (%) pattern错误处理
- 判断两个二叉树是否相等(仅结构) -- 递归和非递归实现
- Java 构造器研究
- I/O多路转接之select
- [整理]分享一些学术用的搜索引擎
- 第六周
- jumbo安装redis步骤以及redis配置详解
- Java 关闭Thread详解
- (2)Spring Boot返回json数据【从零开始学Spring Boot】
- HackerRank "Angry Children 2"
- 【贪心】HDU2187悼念512汶川大地震遇难同胞——老人是真饿了
- Pentaho Work with Big Data(七)—— 从Hadoop集群抽取数据
- Object-C 属性
- VS调试时同时启动多个项目解决方法
- 关于Keil C51中“ERROR L107: ADDRESS SPACE OVERFLOW ”的总