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;
    }





  • 相关阅读:
    苹果开发者账号证书、授权配置文件设置流程
    JQuery 总结(1) 选择器的使用
    PC和移动端自动识别
    前端获取ip的接口
    AJAX 跨域解决办法
    linux
    复制剪切板实现
    css animation 制作打开动画效果
    弹出层播放视频
    盛世龙图项目总结
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5415791.html
Copyright © 2011-2022 走看看