题解:P10993 【MX-J3-T0】37

· · 题解

本题考点:to_string、unique 和 string::erase 的熟练运用。

我们先将 a 乘上 37,然后用 to_string 函数将 a 转换为字符串。

我们再执行语句 s.erase(unique(s.begin(), s.end()), s.end()); 就可以完成去重操作了。其中,unique 是去重函数,返回去重后的尾迭代器;erase(start, end) 表示删除 start 到 end 前的所有元素。因此,这段语句可以起到去重的作用。

参考代码如下:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    cin >> x;
    x *= 37;
    string ans = to_string(x);
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ((int)ans.size() == 1 ? "Yes" : "No");
}