今天写一道题时回文数判断写的不熟,放个板子在这有时间背一背
//判断回文数
bool isHWS(int num) {
int temp = num, ans = 0;
while (temp > ans) {
ans = ans * 10 + temp % 10;
temp /= 10;
}
return temp == ans || temp == ans / 10;
}
下面这个是字符下的判断
bool isHWS(string s)
{
for(int i = 0; i < s.length() / 2; i ++)
{
if(s[i] != s[s.length() - 1 - i]) return false;
}
return true;
}