一道模拟题,来模拟进位

暴力的从右往左扫描,按规则求后继就好了。除了Sample已给出的,还有一些需要注意的地方:

  • 9的后继是10,而不是00;
  • (z)的后继是(aa),而不是a(a);
  • 输入虽然最长只有100,但输出最长可能有102。

事实上题目中给的字符串后继规则,也是Ruby中String#succ或String#next所用的规则

http://blog.watashi.ws/1944/the-8th-zjpcpc/

标程也写的非常好

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; string str;
int n; bool exist () {
for (int i = ; i < str.size(); ++i) {
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z' || str[i] >='' && str[i] <= '') return true;
}
return false;
} bool exist (char ch) {
return ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '' && ch <='';
} int main(){
std::ios::sync_with_stdio(false);
int i, j, t, k, u, v, numCase = ;
int flag; cin >> t;
while (t--) {
cin >> str >> n;
while (n--) {
if (exist ()) {
flag = ;
for (i = str.size () - ; i >= ; --i) {
if (exist (str[i])) {
if (str[i] == '' || str[i] == 'Z' || str[i] == 'z') {
for (j = ; j < i; ++j) {
if (exist (str[j])) break;
}
if (j == i && j != ) { if (str[i] == '') {
flag = ;
str[i] = '';
} else if (str[i] == 'Z') {
flag = ;
str[i] = 'A';
} else if (str[i] == 'z') {
flag = ;
str[i] = 'a';
} if (flag) {
if ( == flag) {
string tmp;
for (k = ; k < i; ++k) tmp.push_back(str[k]);
tmp.push_back('');
for (k = i; k < str.size(); ++k) tmp.push_back(str[k]);
str = tmp;
}
if ( == flag) {
string tmp;
for (k = ; k < i; ++k) tmp.push_back(str[k]);
tmp.push_back('A');
for (k = i; k < str.size(); ++k) tmp.push_back(str[k]);
str = tmp;
}
if ( == flag) {
string tmp;
for (k = ; k < i; ++k) tmp.push_back(str[k]);
tmp.push_back('a');
for (k = i; k < str.size(); ++k) tmp.push_back(str[k]);
str = tmp;
}
}
flag = ; break;
} else {
if (str[i] == '') {
flag = ;
str[i] = '';
} else if (str[i] == 'Z') {
flag = ;
str[i] = 'A';
} else if (str[i] == 'z') {
flag = ;
str[i] = 'a';
}
}
} else {
flag = ;
++str[i]; break;
}
}
} if (flag) {
if ( == flag) {
string tmp;
tmp.push_back('');
for (i = ; i < str.size(); ++i) tmp.push_back(str[i]);
str = tmp;
}
if ( == flag) {
string tmp;
tmp.push_back('A');
for (i = ; i < str.size(); ++i) tmp.push_back(str[i]);
str = tmp;
}
if ( == flag) {
string tmp;
tmp.push_back('a');
for (i = ; i < str.size(); ++i) tmp.push_back(str[i]);
str = tmp;
}
} cout << str << endl;
} else {
++str[str.size () - ];
cout << str << endl;
}
} cout << endl;
} return ;
}

ZOJ 3490 String Successor 字符串处理的更多相关文章

  1. ZOJ 3490 String Successor

    点我看题目 题意 : 给你一个字符串,让你按照给定规则进行处理. 如果字符串里有字母或者是数字就忽略非字符数字,如果没有,就让最右边的那个字符+1. 增量都是从最右边的字母或者数字开始的. 增加一个数 ...

  2. ZOJ 3490 String Successor(模拟)

    Time Limit: 2 Seconds Memory Limit: 65536 KB The successor to a string can be calculated by applying ...

  3. ZOJ——String Successor(字符串模拟题目)

    ZOJ Problem Set - 3490 String Successor Time Limit: 2 Seconds      Memory Limit: 65536 KB The succes ...

  4. .NET面试题解析(03)-string与字符串操作

      系列文章目录地址: .NET面试题解析(00)-开篇来谈谈面试 & 系列文章索引 字符串可以说是C#开发中最常用的类型了,也是对系统性能影响很关键的类型,熟练掌握字符串的操作非常重要. 常 ...

  5. [CareerCup] 1.2 Reverse String 翻转字符串

    1.2 Implement a function void reverse(char *str) in C or C++ which reverses a null-terminated string ...

  6. char型字符串(数组)与string型字符串 指针与引用

    一.常指针: int *const p;    //指针不可改变,但是指针指向的数据可以改变. 指向常量的指针: const int *p;    //指针可以改变,但是指针指向的数据不可以改变. 指 ...

  7. Java基础知识强化59:String(字符串)和其他类型的相互转化

    1. String类型 ---> 其他类型 (1)使用基本类型包装类的parseXXX方法 e.g:String(字符串)转化为int(整型) String MyNumber ="12 ...

  8. String[255]在高版本Delphi里还是被解释成Byte,总体长度256,使用StrPCopy可以给Array String拷贝字符串(内含许多实验测试)

    学了好多不了解的知识: procedure TForm1.Button1Click(Sender: TObject); var s1 : String; s2 : String[]; begin s1 ...

  9. JavaScript String(字符串对象)

    String 对字符串的支持 String.charAt( n ) 返回字符串中的第n个字符 n 是下标 String.charCodeAt( ) 返回字符串中的第n个字符的代码 String.con ...

随机推荐

  1. 全新安装mysql最新版本

    写在前面: 下面写的东西只是最近安装的一个说明,是在系统中没存在mysql的情况下安装的,后期会根据官方文档写一个详细有价值的文档 安装原理:利用mysql官方的mysql_apt-repositor ...

  2. poj 2653 计算几何

    #include <iostream> #include <cstring> #include <algorithm> #include <cmath> ...

  3. Delphi的MDI编程中遇到的一个奇怪问题(值得研究的一个问题)

    近日在用delphi写一个多文档应用程序,除了一个主界面是自动生成的,其他功能页面全部都是通过Application.CreateForm()动态生成的,也就是说在ProjectManager中点击程 ...

  4. HDU 3231 Box Relations

    题目大意: 给定一些正方体的关系,要求一组符合这些关系的正方体坐标,如果不存在符合条件的正方体坐标,IMPOSSIBLE.(Special Judge) 实力还是太弱了,完全不会…… #include ...

  5. hdoj 1028 Ignatius and the Princess III(区间dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 思路分析:该问题要求求出某个整数能够被划分为多少个整数之和(如 4 = 2 + 2, 4 = 2 ...

  6. Python生成随机数的方法

    这篇文章主要介绍了Python生成随机数的方法,有需要的朋友可以参考一下 如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与 ...

  7. Matlab pivotgolf

    function scoreout = pivotgolf(course,pivotstrat) % PIVOTGOLF Pivot Pickin' Golf. % Your goal is to u ...

  8. 一些常用的Intent及intent-filter的信息

    Uri Action 功能 备注 geo:latitude,longitude Intent.ACTION_VIEW 打开地图应用程序并显示指定的经纬度   geo:0,0?q=street+addr ...

  9. Extending your SharePoint 2007 site with Microsoft ASP.NET AJAX 3.5

    After ASP.NET 3.5 has been installed you need to modify the web.config file of your MOSS web site wi ...

  10. 自定义cell时,在宽的手机上显示太窄解决办法

    1.工程设置要如下:见第二个红框,清除launch screan file 后面的内容 2.自定义的cell要设置auto layout 和size clases