zoukankan      html  css  js  c++  java
  • codeforces 665C C. Simple Strings(乱搞)

    题目链接:

    C. Simple Strings

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba,zscoder are simple whereas aa, add are not simple.

    zscoder is given a string s. He wants to change a minimum number of characters so that the string s becomes simple. Help him with this task!

     
    Input
     

    The only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string s consists of only lowercase English letters.

     
    Output
     

    Print the simple string s' — the string s after the minimal number of changes. If there are multiple solutions, you may output any of them.

    Note that the string s' should also consist of only lowercase English letters.

     
    Examples
     
    input
    aab
    output
    bab
    input
    caaab
    output
    cabab
    input
    zscoder
    output
    zscoder

    题意:

    最少次变换,使相邻的字母不一样;

    思路:

    乱搞呗,把不一样的换了不就好了;

    AC代码:
    /*2014300227    665C - 8    GNU C++11    Accepted    31 ms    2240 KB*/
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=2e5+5;
    const ll mod=1e9+7;
    char str[N];
    int main()
    {
        scanf("%s",str);
        int len=strlen(str);
        str[len]='a'-1;
        for(int i=1;i<len;i++)
        {
            if(str[i]==str[i-1])
            {
                for(int j=0;j<26;j++)
                {
                    if(str[i+1]!=j+'a'&&str[i-1]!=j+'a')
                    {
    
                        str[i]=j+'a';
                    }
                }
            }
        }
        for(int i=0;i<len;i++)
        {
            printf("%c",str[i]);
        }
        return 0;
    }





  • 相关阅读:
    mod_rewrite
    敏捷开发
    转python和ruby的相同点
    ESB总线知识小结
    使用 squid 2.7 for windows 进行无缓存反向代理
    初探K2workflow
    没激情的工作
    多易拍 二次开发
    查看数二进制代码片段
    生成随机数
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5415791.html
Copyright © 2011-2022 走看看