Last active
April 7, 2017 04:04
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1034 這題主要是找該數的每位數最大的基底,最後再查看該數能夠被最小基底的數整除的基底數
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
while (scn.hasNext()) { | |
char arr[]=scn.nextLine().trim().toCharArray(); | |
int tot=0,max=1; | |
for(int i=0;i<arr.length;i++){ | |
if(arr[i]>='0'&&arr[i]<='9'){ | |
if(arr[i]-'0'>max){ | |
max=arr[i]-'0'; | |
} | |
tot+=arr[i]-'0'; | |
} | |
else if(arr[i]>='A'&&arr[i]<='Z'){ | |
if(arr[i]-'A'+10>max){ | |
max=arr[i]-'A'+10; | |
} | |
tot+=arr[i]-'A'+10; | |
} | |
else if(arr[i]>='a'&&arr[i]<='z'){ | |
if(arr[i]-'a'+36>max){ | |
max=arr[i]-'a'+36; | |
} | |
tot+=arr[i]-'a'+36; | |
} | |
} | |
int i=0; | |
for(i=max;i<62;i++){ | |
if(tot%i==0){ | |
System.out.println(i+1); | |
break; | |
} | |
} | |
if(i==62) | |
System.out.println("such number is impossible!"); | |
} | |
} | |
/*題目:Q10093: An Easy Problem! | |
作者:1010 | |
時間:西元 2017 年 4 月 7日*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment