题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小。

析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果到最后一位了还没开始减,

就减最后一位。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e8;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, -1, 1, 1, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
char s[maxn]; int main(){
while(scanf("%s", s) == 1){
int len = strlen(s);
int ok = false;
for(int i = 0; i < len; ++i){
if(s[i] =='a' && ok) break;
if(i == len-1 && !ok){
s[i] = (s[i]-'a'+25) % 26 + 'a';
break;
}
if(s[i] != 'a'){
ok = true;
--s[i];
}
}
printf("%s\n", s);
}
return 0;
}

最新文章

  1. 20145205 《Java程序设计》第8周学习总结
  2. oracle里面base64加解密
  3. 优秀开源代码解读之JS与iOS Native Code互调的优雅实现方案
  4. 44. Decode Ways &amp;&amp; Gray Code
  5. SQL server 2008数据库的备份与还原(转)
  6. Android开发手记(10) 下拉菜单Spinner
  7. 安徽省2016“京胜杯”程序设计大赛_A_砝码称重
  8. Day 1 Python简单程序
  9. layui获取子集表单中的值,关闭父级弹窗
  10. 使用Mybatis时mybatis-config.xml配置中&quot;configuration&quot; 的内容必须匹配 (.....)解决方案
  11. 1.2 eigen中矩阵和向量的运算
  12. Python3NumPy——ndarray对象
  13. Redis常见操作命令
  14. cocos2d-x 3.0 WIN7+VS2012 安卓平台搭建
  15. logback-kafka-appender
  16. [Learn AF3]第二章 App Framework 3.0的组件View——AF3的驱动引擎
  17. [原][osg][osgEarth][粒子特效]关于粒子特效库在osgEarth中,位置摆放问题,跟踪节点移动问题
  18. BZOJ1821:[JSOI2010]部落划分(并查集,二分)
  19. apache poi根据模板导出excel
  20. VUE环境搭建及打包上线

热门文章

  1. Python [Leetcode 121]Best Time to Buy and Sell Stock
  2. 【英语】Bingo口语笔记(40) - [aʊ]的发音规则
  3. AIX 第4章 指令记录
  4. Heritrix源码分析(三) 修改配置文件order.xml加快你的抓取速度(转)
  5. EIG集团简单介绍
  6. Spring中WebApplicationContext的研究
  7. 【转】在Eclipse中使用PyDev进行Python开发
  8. Fidder 监控WCF
  9. python 字典items和iteritems
  10. redmine 2.5.2 安装后邮件无法发送