zl程序教程

您现在的位置是:首页 >  其它

当前栏目

AT2153 [ARC064B] An Ordinary Game 题解

an 题解 Game
2023-06-13 09:12:17 时间

题目链接 : AT2153 [ARC064B] An Ordinary Game

一道大水题

这题有个挺重要的点,需要注意 :

  • Remove one of the characters in s , excluding both ends.
  • 删除 s 中的一个字符,不包括两端。

通过观察可发现,如果输入的字符串长度是偶数,且 s 两端是相等的字符串,则 ans = "First",否则的话,ans = "Second";当输入的字符串长度是奇数,且 s 两端是相等的字符串,则 ans = "First",否则的话,ans = "Second"。

判断 s 两端是相等时,可以用 s.front() == s.back(),具体请 bdfs(百度优先搜索)。

Code:

#include <iostream> // 不要忘记 cstring 头文件 
#include <cstring>

int main()
{
    std::string ans; // ans 记录答案 
    std::string s;
    std::cin >> s;
    
    if (s.length() % 2) // len 为奇数时
    {
        ans = (s.front() == s.back()) ? "Second" : "First";
    }
    else // len 为偶数时
    {
        ans = (s.front() == s.back()) ? "First" : "Second";
    } // 先判断奇偶, 再判断首尾 
    
    std::cout << ans << std::endl;
    return 0;
}