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 ...
随机推荐
- Linux中的常见命令
1. ls 查看当前目录下的所有文件夹 2. pwd 查看当前所在的文件夹 3. cd 目录名 切换文件夹 4. touch 文件名 创建文件 5. mkdir 目录名 创建文件夹 6 ...
- 分享几个简单的技巧让你的 vue.js 代码更优雅
1. watch 与 computed 的巧妙结合 一个简单的列表页面. 你可能会这么做: created(){ this.fetchData() }, watch: { keyword(){ thi ...
- phpExcel使用方法二
require_once './phpexcel/PHPExcel.php'; // 首先创建一个新的对象 PHPExcel object $objPHPExcel = new PHPExcel(); ...
- 9-11.Yii2.0框架控制器分配视图并传参xss攻击脚本视图的过滤
目录 一维数组传参 新建控制器: 新建view模板 二维数组传参 新建控制器: 新建view模板 视图非法字符的过滤 新建控制器: 新建view模板 一维数组传参 新建控制器: D:\xampp\ht ...
- 【Windows7注册码】
[文章转载自 http://www.win7zhijia.cn/jiaocheng/win7_19324.html] 一.神Key: KH2J9-PC326-T44D4-39H6V-TVPBY TFP ...
- 03 Django视图
功能 接受Web请求HttpRequest,进行逻辑处理,与 M 和 T 进行交互,返回 Web 响应 HttpResponse 给请求者 示例项目的创建 创建项目 test3 django-admi ...
- python3中urllib库的request模块详解
刚刚接触爬虫,基础的东西得时时回顾才行,这么全面的帖子无论如何也得厚着脸皮转过来啊! 原帖地址:https://www.2cto.com/kf/201801/714859.html 什么是 Urlli ...
- Phonegap环境配置和安装插件
一:安装好jdk(配置好环境变量) 二:安装好Android SDK(配置好环境变量path F:\Android\android-sdk-windows\platform-tools;F:\Andr ...
- Leetcode7--->Reverse Integer(逆转整数)
题目: 给定一个整数,求将该整数逆转之后的值: 举例: Example1: x = 123, return 321Example2: x = -123, return -321 解题思路: 在这里只用 ...
- [Oracle] Lob介绍
[Oracle] Lob介绍 像Oracle这种关系型数据库,比较擅长处理结构化的数据,那么对于非结构化的数据,Oracle是怎么处理和存储的呢?Lob (Large Object)是Oracle ...