AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心
A. Letters Cyclic Shift
题目连接:
http://www.codeforces.com/contest/708/problem/A
Description
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Sample Input
codeforces
Sample Output
bncdenqbdr
Hint
题意
你可以调整一个子串,使得这个子串的所有字符都往前减小一个字典序,问你能够得到的最小字典序的字符串是哪个
题解:
贪心,从前往后,能变就变。
特判掉全是a的情况就好了
代码
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
int i;
for(i=0;i<s.size();i++)
if(s[i]!='a')break;
int flag = 0;
for(int j=i;j<s.size();j++)
{
if(s[j]=='a')break;
s[j]--;
flag=1;
}
if(i==s.size())s[i-1]='z';
cout<<s<<endl;
}
AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心的更多相关文章
- codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...
- AIM Tech Round 3 (Div. 2) A , B , C
A. Juicer time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- codeforces 709C C. Letters Cyclic Shift(贪心)
题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路 ...
- AIM Tech Round 4 (Div. 2)ABCD
A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- AIM Tech Round 3 (Div. 2)
#include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...
- AIM Tech Round 3 (Div. 2) A B C D
虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...
- AIM Tech Round 3 (Div. 2) B
Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...
随机推荐
- nginx配置伪静态
最近做门户网站,使用了的nginx重写规则 项目目录下写好 nginx.conf文件 然后在打开nginx配置文件,在server引入对应的重写规则的文件就可以了 当然直接写在配置里面 locatio ...
- [转载]Windows 8 VHD 概述与使用
http://www.cnblogs.com/tonycody/archive/2012/11/30/2796858.html
- zTree的简单例子
<%@ page language="java" pageEncoding="UTF-8" %> <%@ include file=" ...
- 将本地的mongodb迁移到阿里云
首先在阿里云上安装mongodb,可以根据官方教程 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-amazon/ 完成之后启动 ...
- ffmpeg查看音频文件信息
查看音频文件的信息(基于本地路径) import subprocess import json path = r'D:\learn\download\NosVJ60QCIs0b8PVHMPomZJsr ...
- 恶意代码分析实战-PE资源提取
场景 1.提取恶意代码中的资源部分内容 思路 存在Loadresource函数的时候说明有一部分内容在资源里. 技术点 Lab1-4 ResourceHacker打开保存资源,载入IDA查看
- 善用backtrace解决大问题【转】
转自:https://www.2cto.com/kf/201107/97270.html 一.用途: 主要用于程序异常退出时寻找错误原因 二.功能: 回溯堆栈,简单的说就是可以列出当前函数调用关系 三 ...
- 移动端console.log()调试
在微信或app进行开发的时候,没法直接查看console.log的输出内容,调试起来简直太痛苦了. 1.笨笨的方法 fiddler抓请求:追加dom节点,显示调试信息. var div =docume ...
- 神奇的Content-Type--在JSON中玩转XXE攻击
转自:360安全播报http://bobao.360.cn/learning/detail/360.html 大家都知道,许多WEB和移动应用都依赖于Client-Server的WEB通信交互服务.而 ...
- js单元测试框架
js单元测试框架 前端测试框架对比(js单元测试框架对比) 本文主要目的在于横评业界主流的几款前端框架,顺带说下相关的一些内容. 测试分类 通常应用会有 单元测试(Unit tests) 和 功能测试 ...