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

    http://codeforces.com/problemset/problem/946/C

    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

     mmp,题意看半天没看懂。。。

    题意就是通过使用魔法(可将小字母变大),从字符串中抽取26个字母使其组成连续26英文字母

    // 去吧!皮卡丘! 把AC带回来!
    //      へ     /|
    //   /\7    ∠_/
    //   / │   / /
    //  │ Z _,< /   /`ヽ
    //  │     ヽ   /  〉
    //  Y     `  /  /
    //  イ● 、 ●  ⊂⊃〈  /
    //  ()  へ    | \〈
    //   >ー 、_  ィ  │ //
    //   / へ   / ノ<| \\
    //   ヽ_ノ  (_/  │//
    //    7       |/
    //    >―r ̄ ̄`ー―_
    //**************************************
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 2147483647
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    #define ri register int
    template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
    template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
    template <class T> inline T min(T a, T b, T c, T d) {
      return min(min(a, b), min(c, d));
    }
    template <class T> inline T max(T a, T b, T c, T d) {
      return max(max(a, b), max(c, d));
    }
    #define scanf1(x) scanf("%d", &x)
    #define scanf2(x, y) scanf("%d%d", &x, &y)
    #define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
    #define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
    #define pi acos(-1)
    #define me(x, y) memset(x, y, sizeof(x));
    #define For(i, a, b) for (int i = a; i <= b; i++)
    #define FFor(i, a, b) for (int i = a; i >= b; i--)
    #define bug printf("***********
    ");
    #define mp make_pair
    #define pb push_back
    const int maxn = 1e8 + 10;
    const int maxx = 1e6 + 10;
    // name*******************************
    char s[maxn];
    // function******************************
    
    //***************************************
    int main() {
      // ios::sync_with_stdio(0); cin.tie(0);
      // freopen("test.txt", "r", stdin);
      //  freopen("outout.txt","w",stdout);
      scanf("%s", s);
      int len = strlen(s);
      if (len < 26) {
        cout << -1;
        return 0;
      }
      int p=0;
    For(i,0,len-1){
      if(p==26)break;
      if(s[i]<=p+'a'){
        s[i]=p+'a';
        p++;
      }
    }
    if(p==26)
    printf("%s",s );
    else
    cout<<-1;
    
      return 0;
    }
  • 相关阅读:
    ☀【布局】
    _#【CSS3】
    _#minheight
    【其它】引入css
    【css3】url
    鼠标闲置一段时间后自动隐藏
    图解SQLServer2005获取WebService数据
    Oracle字符串字段内的字符排序
    一个c#读取扫雷内存的demo
    sqlserver使用bcp分解字符串
  • 原文地址:https://www.cnblogs.com/planche/p/8568681.html
Copyright © 2011-2022 走看看