zoj3490
来源:互联网 发布:秦可卿怎么死的知乎 编辑:程序博客网 时间:2024/06/08 15:30
#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;}
0 0
- zoj3490
- ZOJ3490-String Successor
- I/O多路转接之select
- Java 构造器研究
- 从数据仓库到数据视图
- BestCoder Round #72 Clarke and chemistry
- chrome浏览器安装
- zoj3490
- 判断两个二叉树是否相等(仅结构) -- 递归和非递归实现
- js页面转码
- IQKeyboardManager的使用笔记
- Navicat for SQL Server有哪些功能
- 小菜鸟成长记
- 推荐-计算机视觉、图像处理方面的论文阅读笔记
- WAP调用微信支付https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1
- Linux-简单的Makefile编写