zoukankan      html  css  js  c++  java
  • Codeforces 946 C.String Transformation

    C. String Transformation
     
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Input

    The only one line of the input consisting of the string s consisting of |s| (1 ≤ |s| ≤ 105) small english letters.

    Output

    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).

    Examples
    input
    Copy
    aacceeggiikkmmooqqssuuwwyy
    output
    abcdefghijklmnopqrstuvwxyz
    input
    Copy
    thereisnoanswer
    output
    -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的题解。

  • 相关阅读:
    分享一组很赞的 jQuery 特效【附源码下载】
    HTML5 Canvas 实现的9个 Loading 效果
    Charted – 自动化的可视化数据生成工具
    jQuery Countdown Timer 倒计时效果
    Droidicon – 1600+ 漂亮的 Android 图标
    tiltShift.js
    推荐12个最好的 JavaScript 图形绘制库
    Elastic Image Slider 带缩略图功能的幻灯片
    12款高质量的响应式 HTML5/CSS3 网站模板
    7种鼠标悬停效果,多样的图片说明展示
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9711411.html
Copyright © 2011-2022 走看看