top1编程
← 返回题目
题解

【入门】判断四位数是否为对称数

1 条题解

  • 0
    @ 2026-7-29 0:16:16
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	//对称数
    	//if(十位 等于 百位 && 个位 等于 千位)
    	//拿到n这个数字
    	int n;
    	cin >> n;   //1234
    	//对n拆解拿到个十百千
    	//想要拿到末位,要使用%10
    	int g,s,b,q;
    	g = n%10;
    	s = n/10%10;
    	b = n/100%10;
    	q = n/1000%10;
    	if(g==q && b==s){
    		cout<<"yes";
    	}else{
    		cout<<"no";
    	}
    	return 0;
    }
    
    • 1