四位回文数

难度:★★★☆☆

一、题目描述

  给出一个四位数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)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值