难度:★★★☆☆
一、题目描述
给出一个四位数n, 判断是否回文数
如果是就是输出"YES",否则输出"NO"。
【样例1输入】
1221
【样例1输出】
YES
【样例2输入】
1211
【样例2输出】
NO
二、解题
1.第一种(小白)
代码有的
#include <bits/stdc++.h>
using namespace std;
int main(){
int num,c=0;
scanf("%d",&num);
int b=num;
while(b>0)
{
c=c*10+b%10;
b/=10;
}
if(num==c)
printf("YES");
else
printf("NO");
return 0;
}
2.第二种(神awa)
代码还有的
#include <bits/stdc++.h>
using namespace std;
bool flag = 0;
int huiwen(int &x) {
int a, b, c, d;
a = x / 1000;
b = x / 100 % 10;
c = x / 10 % 10;
d = x % 10;
if (a == d && b == c)
flag = 1;
return flag;
}
int main() {
int y;
cin >> y;
huiwen(y);
if (flag)
cout << "YES";
else
cout << "NO";
return 0;
}
↑↑↑沉浸式函数(hahaha)

497

被折叠的 条评论
为什么被折叠?



