PAT (Basic Level) 1091 N-自守数 (15分)JAVA解法

在这里插入图片描述

输入样例:

3
92 5 233

输出样例:

3 25392
1 25
No



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] arr = br.readLine().split(" ");
		boolean t = true;
		for (int i = 0; i < n; i++) {
			int len = arr[i].length();
			for (int j = 1; j < 10; j++) {
				String a = (int)(Math.pow(Integer.parseInt(arr[i]), 2)*j)+"";
				//System.out.println(a);
				if(Integer.parseInt(a.substring(a.length()-len,a.length()))==Integer.parseInt(arr[i])){
					System.out.println(j+" "+a);
					t=false;
					break;
				}
			}
			if(t) {
				System.out.println("No");
			}else {
				t=true;
			}
			
		}
		
		
		
		
	}

}

在这里插入图片描述

发布了83 篇原创文章 · 获赞 1 · 访问量 1018

猜你喜欢

转载自blog.csdn.net/qq_44028719/article/details/103992889