Created
September 19, 2017 15:08
-
-
Save BalicantaYao/98d538f7ed92359bf9c8524d648af925 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package hello; | |
public class OCR { | |
public static void main(String[] args) | |
{ | |
String first = "ba6"; | |
String second = "1Ad"; | |
boolean res = Ocr(first, second); | |
System.out.println(countingWordsLength(first)); | |
} | |
private static int countingWordsLength(String str){ | |
int length = 0; | |
for (int i = 0; i < str.length() ; i++) { | |
char c = str.charAt(i); | |
if(Character.isDigit(c)){ | |
length += Character.getNumericValue(c); | |
}else{ | |
length++; | |
} | |
} | |
return length; | |
} | |
public static boolean Ocr(String first, String second) | |
{ | |
if (countingWordsLength(first) != countingWordsLength(second)) | |
{ | |
return false; | |
} | |
char[] mirror = new char[first.length()]; | |
for (int i = 0; i < first.length(); i++) | |
{ | |
if (!Character.isDigit(first.charAt(i))) | |
{ | |
mirror[i] = first.charAt(i); | |
} | |
} | |
for (int i = 0; i < second.length(); i++) | |
{ | |
if (Character.isDigit(second.indexOf(i))) | |
{ | |
continue; | |
} | |
if (Character.isSpaceChar(mirror[i]) == false && !Character.isDigit(mirror[i]) && second.charAt(i) != mirror[i]) | |
{ | |
return false; | |
} | |
} | |
return true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment