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 ...
随机推荐
- vtigercrm安装
vtigercrm是一个用户关系管理系统. 本以为安装只用半个小时就可以完成,结果花了两天时间.. 后来因为不想其他的因素影响,重新装了个纯净的系统.(系统为ubuntu16,安装过程略) 在系统基础 ...
- 第3-5课 填充左侧菜单/品牌的添加 Thinkphp5商城第四季
目录 左侧菜单的填充 品牌的添加 form标签里要加上method="post" enctype="multipart/form-data" form标签里如果 ...
- freertos知识点笔记——队列、二值信号量、计数信号量
队列1.队列queue通常用于任务之间的通信,一个任务写缓存,另一个任务读缓存.队列还会有等待时间,2.阻塞超时时间.如果在发送时队列已满,这个时间即是任务处于阻塞态等待队列空间有效的最长等待时间.如 ...
- NTC温度采集之数据拟合——freemat软件实现
在stm32温度采样的过程中,使用到了NTC传感器,上拉接6.2K的电阻,信号给AD采样端口,通过NTC的电阻阻值表中,计算得到下面两端数据,在freemat中实现数据拟合,用于程序中温度和电压信号的 ...
- ubuntu12.04 ppa安装pidgin
sudo apt-get update sudo apt-get dist-upgrade sudo add-apt-repository ppa:pidgin-developers/ppa按下回车 ...
- Markdown 使用锚点
首先是建立一个跳转的连接: [说明文字](#jump) 然后标记要跳转到什么位置即可: <span id = "jump">跳转到这里:</span>
- Tarjan算法及其应用
Tarjan算法及其应用 引入 tarjan算法可以在图上求解LCA,强连通分量,双联通分量(点双,边双),割点,割边,等各种问题. 这里简单整理一下tarjan算法的几个应用. LCA http:/ ...
- python - work5 - 类与对象
# -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: work_20181119.py@ide: PyCharm Communit ...
- FastText 介绍
FastText 介绍 在面试百度的NLP工程师时,被问及常用的词向量表示学习方法有哪些,我说知道word2vec,然后大佬又问我知道FastText么... 这就很尴尬了,不会! 不同于word2v ...
- docker容器为什么可以跨平台部署
docker镜像和操作系统没关系,docker最大的价值就是提出了镜像打包技术.首先你的明白什么是docker,什么是镜像,什么是容器,然后你就能明白镜像和操作系统之间的关系.docker是一个引擎, ...