1091 N-自守数 较简单

代码

#include <iostream>
#include <cstdio>
#include <string> 
using namespace std;

int main()
{
	int m;
	int a;
	int tmp;
	int tmp3;
	int tmp4;
	int tmp5;
	int f;
	string s;
	cin>>m;
	for(int i=0;i<m;i++){
		f=0;
		cin>>a;//1~1000
		tmp=0;//a的位数 
		tmp5=a;
		while(tmp5!=0){
			tmp5/=10;
			tmp++;
		}
		for(int j=1;j<10;j++){
			s=to_string(a*a*j);
			tmp3=0;
			tmp4=1;
			for(int tmp2=s.size()-1;(tmp2>=s.size()-tmp)&&tmp2>=0;tmp2--){
				tmp3+=(s[tmp2]-'0')*tmp4;
				tmp4*=10;
			}
			if(tmp3==a){
				cout<<j<<" "<<s<<endl;
				f=1;
				break;
			}
		}
		if(f==0){
			cout<<"No"<<endl;
		}
	}
	return 0;
}
posted @ 2022-07-14 10:46  qwasdasd  阅读(27)  评论(0)    收藏  举报