Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab_6;
- public class Decoder {
- public static void main(String[] args)
- {
- String word = "����";
- String result = "����";
- try {
- Decoder.decode(word, result);
- } catch (Exception exc) {
- System.out.println(exc);
- }
- }
- public static void decode(String word, String result)
- {
- int sum;
- int count = 0;
- for (int firstIndex = 123; firstIndex < 987; firstIndex++) {
- for (int secondIndex = 123; secondIndex < 987; secondIndex ++)
- {
- if (isRepeated(Integer.toString(firstIndex), Integer.toString(secondIndex))) {
- continue;
- }
- sum = firstIndex + secondIndex;
- if (sum > 9876) {
- continue;
- }
- if (isRepeated(Integer.toString(firstIndex), Integer.toString(sum)))
- {
- continue;
- }
- if (isRepeated(Integer.toString(secondIndex), Integer.toString(sum)))
- {
- continue;
- }
- if (Integer.toString(firstIndex).split("")[0] == Integer.toString(sum).split("")[2]) {
- continue;
- }
- count++;
- System.out.println(firstIndex + " + " + secondIndex + " = " + sum);
- }
- }
- System.out.println("�������: " + count);
- }
- private static boolean isRepeated(String firstString, String secondString)
- {
- String[] firstStringArray = firstString.split("");
- for (String firstLetter: firstStringArray)
- {
- if (!stringIsValid(firstString))
- {
- return true;
- }
- if (!stringIsValid(secondString))
- {
- return true;
- }
- if (secondString.indexOf(firstLetter) != -1)
- {
- return true;
- }
- }
- return false;
- }
- private static boolean stringIsValid(String string)
- {
- String[] letters = string.split("");
- String substring;
- int index = 0;
- while (index < letters.length - 1)
- {
- substring = string.substring(index);
- if (string.substring(index + 1).indexOf(letters[index]) != -1)
- {
- return false;
- }
- index++;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement