您的位置:首页 > 其它

Codeforces Round #265 (Div. 2) C - No to Palindromes!

2014-11-01 15:50 459 查看
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

const int N = 1005;

char c
;

int main()
{
    int n, p;
    while(~scanf("%d%d", &n, &p))
    {
        scanf("%s", c);
        int pos = n - 1;
        c[pos]++;
        while( pos >= 0 && pos < n )
        {
            if( c[pos] >= 'a' + p)
            {
                c[pos] = 'a';
                c[--pos] ++;
            }
            else if( c[pos] == c[pos-1] && pos >= 0 || c[pos] == c[pos - 2] && pos >= 1 )
            {
                c[pos]++;
            }
            else
            {
                pos++;
            }
        }
        if(pos > 0)
            printf("%s\n", c);
        else
            printf("NO\n");
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: