Codeforces 946 C.String Transformation
1 second
256 megabytes
standard input
standard output
You are given a string s consisting of |s| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.
The only one line of the input consisting of the string s consisting of |s| (1 ≤ |s| ≤ 105) small english letters.
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
aacceeggiikkmmooqqssuuwwyy
abcdefghijklmnopqrstuvwxyz
thereisnoanswer
-1
1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cmath>
5 #include<algorithm>
6 #include<cstdlib>
7 using namespace std;
8 typedef long long ll;
9 const int maxn=1e5+10;
10 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
11 int main(){
12 string s;
13 ios;
14 cin>>s;
15 int len=s.length();
16 int tmp=0;
17 for(int i=0;i<len;i++){
18 if(s[i]-'a'<=tmp){
19 tmp++;s[i]='a'+tmp-1;
20 }
21 if(tmp==26)break;
22 }
23 if(tmp==26)cout<<s<<endl;
24 else cout<<"-1"<<endl;
25 }
溜了,滚去写D的题解。
Codeforces 946 C.String Transformation的更多相关文章
- CCPC2018-湖南全国邀请赛 G String Transformation
G.String Transformation 题目描述 Bobo has a string S = s1 s2...sn consists of letter a , b and c . He ca ...
- Codeforces 1383C - String Transformation 2(找性质+状压 dp)
Codeforces 题面传送门 & 洛谷题面传送门 神奇的强迫症效应,一场只要 AC 了 A.B.D.E.F,就一定会把 C 补掉( 感觉这个 C 难度比 D 难度高啊-- 首先考虑对问题进 ...
- Codeforces 109D String Transformation 字符串 哈希 KMP
原文链接https://www.cnblogs.com/zhouzhendong/p/CF109D.html 题目传送门 - CF109D 题意 给定两个字符串 $a,b$ ,求一组 $i,j$ 使得 ...
- C. String Transformation
http://codeforces.com/problemset/problem/946/C You are given a string s consisting of |s| small engl ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- Codeforces 797C - Minimal string
C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second m ...
- Codeforces Round 486C - Palindrome Transformation 贪心
C. Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces 825F F. String Compression dp+kmp找字符串的最小循环节
/** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: d ...
随机推荐
- 单例模式的几种实现-Java版
目录 关键点 饿汉式 懒汉式 双检锁 静态内部类单例模式 枚举方式 关键点 私有化构造器 通过静态方法或枚举返回单例类对象 确保单例类对象只有一个,尤其在多线程环境下. 确保每个类被序列化不会重新创建 ...
- GTX 750等低配显卡如何玩转Deepfakes?
这里说的Deepfakes软件还是DeepFaceLab,人工智能换脸,是使用深度学习方法来实现的.而深度学习程序对电脑配置要求是非常高的,尤其是跑模型这个环节.很多低配电脑,根本就跑步起来.比如像G ...
- 《linux设备驱动开发详解》笔记——10中断与时钟
10.1 中断与定时器 中断一般有如下类型: 内部中断和外部中断:内部中断来自CPU,例如软件中断指令.溢出.除0错误等:外部中断有外部设备触发 可屏蔽中断和不可屏蔽中断 向量中断和非向量中断,ARM ...
- Python基础(六)——面向对象编程
(1)定义类和实例 这一部分难得和 Java 较为一致,直接写个例子: class Stu: def __init__(self, name, id): # 构造方法 self.name = name ...
- [译]The Python Tutorial#6. Modules
[译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使 ...
- vim中,在编辑模式下如何快速移动光标
编辑 ~/.vimrc 配置文件,加入如下行,编辑模式下自定义的快捷键 inoremap <C-o> <Esc>o inoremap <C-l> <Righ ...
- STM32CUBEMX入门学习笔记3:HAL库以及STM32CUBE相关资料
微雪课堂:http://www.waveshare.net/study/article-629-1.html 之前的正点原子的例程资料 硬石科技stm32cube: 链接:https://pan.ba ...
- 逻辑与(&)和短路与(&&)的关系
逻辑与(&)和短路与(&&)在运算上对条件的结果判断不会产生影响,但会对条件判断的运算有影响.关键在于,逻辑与(&)在运算时会连续运算所有需要判断的命令.但短路与当遇到 ...
- 大数据学习——scala类相关操作
1 类的定义 package com /** * Created by Administrator on 2019/6/3. */ //类并不用声明为public. class Person { // ...
- day03_12 缩进介绍
python比较变态,必须缩进,而C可以不缩进,世界上只有python这门语言要求必须缩进 tab键是缩进,shift+tab往左移动 SyntaxError:invalid syntax 语法错误 ...