题解 | 守形数

守形数

https://www.nowcoder.com/practice/99e403f8342b4d0e82f1c1395ba62d7b

#include <iostream>
#include <string>
using namespace std;
#include <cstdio>
#include <algorithm>
int main() {
    int n;
    while(cin>>n){
        int sqaure=n*n;
        string s=to_string(sqaure);
        string target=to_string(n);
        bool isok=false;
        for(int i=s.size()-1;i>0;i--){   
            if(s.substr(i)==target){   //逐段截取后边部分,如果等于 平方前 则是
               isok=true;   
            } 
        }
        if(isok){
            cout<<"Yes!"<<endl;
        }else{
            cout<<"No!"<<endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务