论判断回文数 C++ 与 C++ 的区别:#include <iostream>
int main(){return (std::cout << "请输入一个三位数:" << ((std::cin.get() == (std::cin.ignore(), std::cin.get())) ? "是" : "不是") << "回文数\n"), 0;}
什么,只能处理三位数?来试试这个威力加强版:#include <iostream>
int main(){return (std::cout << "请输入一个三位数:" << ((([](std::string v){return ([](std::string v, std::string t){return v==t;})({v.begin(), v.end()-(v.back()=='\n'?1:0)},{v.rbegin()+(v.back()=='\n'?1:0),v.rend()});})({std::istream_iterator<char>(std::cin), std::istream_iterator<char>()})) ? "是" : "不是") << "回文数\n"), 0;}
|