第一行输入一个整数
表示测试数据组数,每组测试数据描述如下:
接下来一行输入一个整数
表示待判断的数字。
对于每一组测试数据,在一行上输出对应的情绪类型
、
或
。
3 72 73 12
H S G
对于
,其数字集合为
;
能被
整除但不能被
整除,因此输出
。
对于
,其数字集合为
;
不能被
也不能被
整除,因此输出
。
对于
,其数字集合为
;
能被
和
都整除,因此输出
。
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
long n = Integer.valueOf(sc.nextLine());
for(int i =0;i<n;i++){
String str = sc.nextLine();
long num = Long.parseLong(str);
int total = 0;
int length = str.length();
for(int j =0;j<length;j++){
int value = str.charAt(j)-48;
if(value==0){
total++;
}else if(num%value==0)total++;
}
outPut(total,length);
}
}
}
public static void outPut(int total,int length){
if(total==length){
System.out.println("G");
}else if(total>0){
System.out.println("H");
}else{
System.out.println("S");
}
}
} /*
思路:利用标志的方式判断,创建两个标志,当能够整除任一个部分数字,该标志为true,
当不能整除任一个部分数字,该标志为true
这样通过两个标志的组合便可以得到结果
注意除数为0的情况
*/
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 m = Integer.parseInt(br.readLine());
long[] arr = new long[m];
for(int i = 0;i<m;i++)
arr[i] = Long.parseLong(br.readLine());
for(int i = 0;i<m;i++){
boolean onenum = false;
boolean nonum = false;
long temp = arr[i];
while(temp > 0){
long divi = temp%10;
if(divi == 0 || arr[i]%divi == 0){
onenum = true;
}else{
nonum = true;
}
temp = temp/10;
}
if(onenum == true && nonum == true){
System.out.println("H");
}else if(onenum == false && nonum == true){
System.out.println("S");
}else if(onenum == true && nonum ==false)
System.out.println("G");
}
}
}