题解 | #对称平方数#

对称平方数

https://www.nowcoder.com/practice/1b79865e2f534db0adba84dca10d6bae

#include <bits/stdc++.h>
using namespace std;

bool ispalindrome(int x){
	stack<int> s;
	queue<int> q;
	while(x){
		s.push(x % 10);
		q.push(x % 10);
		x /= 10; 
	}
	while(!s.empty()){
		if(s.top() != q.front())
			return false;
		s.pop();
		q.pop();
	}
	return true;
}

int main(){
	for(int i = 1; i <= 256; i++){
		if(ispalindrome(i*i)){
			cout<<i<<endl;
		}
	}
	
}

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务