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;
    }
  • 相关阅读:
    ASP.NET 4的Demo实践:URL“.NET研究”路由改进支持 狼人:
    在.NET Workflo“.NET研究”w 3.5中使用多线程提高工作流性能 狼人:
    Reg“.NET研究”exOptions.Compiled的含义和使用 狼人:
    ASP.“.NET研究”NET MVC3 on Mono的折腾(二):Linux(openSUSE)下的部署 狼人:
    C#编程笔记(一)“.NET研究” 狼人:
    Sh“.NET研究”arePoint开发笔记SharePoint2010添加ASP.NET应用程序 狼人:
    分享在MVC3.0中使用jQue“.NET研究”ry DataTable 插件 狼人:
    Silverlight 游戏开发“.NET研究”小技巧:血条和进度条 狼人:
    .N“.NET研究”ET中的异步编程(二) 传统的异步编程 狼人:
    不错的VS2010扩展——JSEnhancements,让js和c“.NET研究”ss也折叠 狼人:
  • 原文地址:https://www.cnblogs.com/planche/p/8568681.html
Copyright © 2011-2022 走看看