ACM模版

描述

题解

这个题大胆的蒙就是了……只有三种结果 0nn1 0 、 n 、 n − 1 ,对于全部是同样字母的,结果是 0 0 ,对于不是回文串的,输出 n ,对于是回文串的输出 n1 n − 1 ,完美解决。

这个题拼的就是读题速度,因为他的样例已经给出了所有可能……开局五分钟一千多 AC A C 好像。

代码

#include <iostream>
#include <string>

using namespace std;

string s;

int main(int argc, const char * argv[])
{
    while (cin >> s)
    {
        int flag = 1;
        for (int i = 0, j = (int)s.length() - 1; i <= j; i++, j--)
        {
            if (s[i] != s[j])
            {
                flag = 0;
                break;
            }
        }

        if (!flag)
        {
            cout << s.length() << '\n';
        }
        else
        {
            flag = 1;
            for (int i = 1; i < s.length(); i++)
            {
                if (s[i] != s[0])
                {
                    flag = 0;
                    break;
                }
            }

            if (flag)
            {
                cout << 0 << '\n';
            }
            else
            {
                cout << s.length() - 1 << '\n';
            }
        }
    }

    return 0;
}