Created
September 3, 2013 14:33
-
-
Save w00lf/6424742 to your computer and use it in GitHub Desktop.
****************Наименьшая система счисления****************
http://acmp.ru/index.asp?main=task&id_task=315
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.io.*; | |
import java.util.*; | |
public class Main{ | |
public static void main(String[] argv) throws IOException,Exception{ | |
new Main().run(); | |
} | |
public void run() throws IOException,Exception{ | |
BufferedReader sc = new BufferedReader(new FileReader("input.txt")); | |
String[] str = sc.readLine().split("(?!^)"); | |
Map<String, Integer> dict = new HashMap(); | |
for (int i = 0; i < 10; i++) { | |
if (i == 0 || i == 1) { | |
dict.put(Integer.toString(i), 2); | |
}else { | |
dict.put(Integer.toString(i), i+1); | |
} | |
} | |
int uppercase = 65; | |
int lowercase = 97; | |
for (int i = 11; i < 37; i++) { | |
dict.put(Character.toString ((char) uppercase++), i); | |
dict.put(Character.toString ((char) lowercase++), i); | |
} | |
int result = 0; | |
for (String string : str) { | |
if (string.matches("[^a-zA-Z0-9]")) { | |
result = -1; | |
break; | |
} | |
if (dict.containsKey(string)) { | |
if (dict.get(string) > result) { | |
result = dict.get(string); | |
} | |
} | |
} | |
PrintWriter pw = new PrintWriter(new File("output.txt")); | |
pw.print(result); | |
pw.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment