UVA 10093 Java

  1. import java.util.*;
  2. import static java.lang.System.*;
  3.  
  4. public class main{
  5. public static void main(String[] args) {
  6. Scanner sc=new Scanner(System.in);
  7. while(sc.hasNextLine())
  8. {
  9. String str = sc.nextLine();
  10. int sum = 0;
  11. int max = 1;
  12. int r = 0;
  13. for(int i =0; i < str.length(); i++)
  14. {
  15. char c = str.charAt(i);
  16. if(c >= '0' && c <= '9')
  17. r = c - '0';
  18. else if(c >= 'A' && c <= 'Z')
  19. r = c - 'A' + 10;
  20. else if(c >= 'a' && c <= 'z')
  21. r = c - 'a' + 36;
  22. sum += r;
  23. if(r > max)
  24. max = r;
  25. }
  26. for(int i = max; i <= 62; i++)
  27. {
  28. if(sum % i == 0)
  29. {
  30. System.out.println(i+1);
  31. break;
  32. }
  33. else if(i == 62)
  34. System.out.println("such number is impossible!");
  35. }
  36. }
  37. }
  38. };
  39.  

留言

這個網誌中的熱門文章

C# 井字遊戲