tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
31
Task/SEDOLs/Java/sedols.java
Normal file
31
Task/SEDOLs/Java/sedols.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class SEDOL{
|
||||
public static void main(String[] args){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
while(sc.hasNext()){
|
||||
String sedol = sc.next();
|
||||
System.out.println(sedol + getSedolCheckDigit(sedol));
|
||||
}
|
||||
}
|
||||
|
||||
private static final int[] mult = {1, 3, 1, 7, 3, 9};
|
||||
|
||||
public static int getSedolCheckDigit(String str){
|
||||
if(!validateSedol(str)){
|
||||
System.err.println("SEDOL strings must contain six characters with no vowels.");
|
||||
return -1;
|
||||
}
|
||||
str = str.toUpperCase();
|
||||
int total = 0;
|
||||
for(int i = 0;i < 6; i++){
|
||||
char s = str.charAt(i);
|
||||
total += Character.digit(s, 36) * mult[i];
|
||||
}
|
||||
return (10 - (total % 10)) % 10;
|
||||
}
|
||||
|
||||
public static boolean validateSedol(String str){
|
||||
return (str.length() == 6) && !str.toUpperCase().matches(".*?[AEIOU].*?");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue