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 ...
随机推荐
- SQL语句(八)按条件查询
SELECT * FROM student SELECT sclass, snumb, sname FROM student --物理班有哪些同学 --年龄小于20岁的有哪些同学? --定价在30元以 ...
- vue注册全局属性
例:统一引用getSpiderToken方法 main.js中相关代码 import { getSpiderToken } from '../static/js/storage' Vue.protot ...
- BAT及各大互联网公司2014前端笔试面试题--Html,Css篇(昨天有个群友表示写的简单了点,然后我无情的把他的抄了一遍)
某个群友 http://www.cnblogs.com/coco1s/ 很多面试题是我自己面试BAT亲身经历碰到的.整理分享出来希望更多的前端er共同进步吧,不仅适用于求职者,对于巩固复习前端基础 ...
- shell 循环数组
循环数组 ;i<${#o[*]};i++)) do echo ${o[$i]} done
- expect 交互 模拟ssh 登陆
模拟ssh登录 #!/bin/bash Ip='192.168.1.6' # 循环就行 RemoteUser='user' # 普通用户 RemotePasswd='userpasswd' # 普通用 ...
- python之celery使用详解(二)
前言 前面我们了解了celery的基本使用后,现在对其常用的对象和方法进行分析. Celery对象 核心的对象就是Celery了,初始化方法: class Celery(object): def __ ...
- Linux下利用backtrace追踪函数调用堆栈以及定位段错误【转】
转自:https://www.linuxidc.com/Linux/2012-11/73470p2.htm 通常情况系,程序发生段错误时系统会发送SIGSEGV信号给程序,缺省处理是退出函数.我们可以 ...
- ipsec-tools安装教程
ipsec-tools最新版本为0.8.2,此处以0.7.3版本为例说明安装和使用过程.可参考ipsec-howto. 安装步骤 ipsec-tools依赖于linux2.6版本内核,在安装ipsec ...
- css1-puchong1
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. 一:HTML DOM 树 ...
- Java中static关键字概述
例如一个学生类中,我们需要统计下学生类中学生对象的数量,此时数量要定义为静态变量: 示例代码: package com.java1995; public class Student { int id= ...