守形数 题解:长度判定用求模方法计算
- #include <bits/stdc++.h>
- using namespace std;
-
- bool judge(int x){
- int y=x*x;
- int size=1;
- int t=x;
- while(x!=0){
- size*=10;
- x/=10;
- }
- y%=size;
- return t==y;
- }
-
- int main() {
- int x;
- while(cin>>x){
- if(judge(x))cout<<"Yes!"<<endl;
- else cout<<"No!"<<endl;
- }
-
- }
-
登录后发布评论
暂无评论,来抢沙发