• PAT (Basic Level) Practice (中文) 1091 N-自守数 (15分)


    1.题目

    如果某个数 K 的平方乘以 N 以后,结果的末尾几位数等于 K,那么就称这个数为“N-自守数”。例如 3×92​2​​=25392,而 25392 的末尾两位正好是 92,所以 92 是一个 3-自守数。

    本题就请你编写程序判断一个给定的数字是否关于某个 N 是 N-自守数。

    输入格式:

    输入在第一行中给出正整数 M(≤20),随后一行给出 M 个待检测的、不超过 1000 的正整数。

    输出格式:

    对每个需要检测的数字,如果它是 N-自守数就在一行中输出最小的 N 和 NK​2​​ 的值,以一个空格隔开;否则输出 No。注意题目保证 N<10。

    输入样例:

    3
    92 5 233
    

    输出样例:

    3 25392
    1 25
    No
    #include<iostream>
    #include<string>
    #include<cstring>
    using namespace std;
    int main()
    {
    	int n, temp, count = 0;
    	cin >> n;
    	for (int i = 0; i < n; i++)
    	{
    		cin >> temp; bool fin = false; int j;
    		for ( j = 0; j < 10; j++)
    		{
    			count = 0;
    			string a = to_string(temp);
    			string b = to_string(temp*temp*j);
    			if (a.length() > b.length())continue;
    			for (int k = a.length() - 1,t=b.length()-1; k >= 0; k--,t--)
    			{
    				if (a[k] == b[t]) count++;
    				else break;
    			}
    			if (count == a.length())
    			{
    				fin = true; break;
    			}
    		}
    		if (fin)cout << j << ' ' << temp*temp*j << endl;
    		else cout << "No" << endl;
    	}
    
    
    }
  • 相关阅读:
    Class类
    HTML表单格式化
    HTML表单组件
    html常用标签
    Html概述
    Myeclipse2016安装Aptana
    长元音
    对比法记音标
    Java基础八--构造函数
    WPS2012交叉引用技巧,word比wps这点强更新參考文献
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788900.html
Copyright © 2020-2023  润新知