//解码摩尔斯i摩尔斯电码(自备摩尔斯电码字典包)
//判断一个字符串是否包含全部26个英文字母。
//输入int数,转化成格式化的时间段。
public static String decode(String morseCode) {////解码摩尔斯i摩尔斯电码(自备摩尔斯电码字典包)
int i=0;
for(i=0;i<morseCode.length()&&Character.isSpaceChar(morseCode.charAt(i));i++){
}
String aaaa = morseCode.substring(i);
String res = "";
int a = 0;
for(String each:aaaa.split(" ")){
if(a>0){
res+=" ";
}else{
a++;
}
if(each!=null){
for(String eacha:each.split(" ")){
res+=MorseCode.get(eacha);
}}
}
return res;
}
public static boolean check(String sentence){//判断一串字符串是否全部包含26个字母
sentence= sentence.replaceAll("[^(A-Za-z)]", "");
sentence.toLowerCase();
String[] set = new String[50];
Set<String> sett = new HashSet<String>();
for(int i=0;i<sentence.toLowerCase().length();i++){
set[i] = "" +sentence.toLowerCase().charAt(i);
System.out.print(sentence.toLowerCase().charAt(i) +"," );
sett.add(set[i]);
}
return sett.size()==26;
}
public static String numbers(int i) { //输入int数,转化成格式化的时间段。
String res = "";
String[][] resd = new String[4][2];
resd[0][0] = i/86400 + ""; resd[0][1] = " day";
resd[1][0] = (i%86400)/3600 + "";resd[1][1] = " hour";
resd[2][0] = ((i%86400)%3600)/60 + "";resd[2][1] = " minute";
resd[3][0]= ((i%86400)%3600)%60 + "";resd[3][1]= " second";
for(i=0;i<=resd.length-1;i++){
if( Integer.parseInt(resd[i][0])<2){
}else{
resd[i][1] += "s";
}
}
for(i=0;i<=resd.length-1;i++){
if(Integer.parseInt(resd[0][0])==0&&Integer.parseInt(resd[1][0])==0&&Integer.parseInt(resd[2][0])==0&&Integer.parseInt(resd[3][0])==0){
res = "now";
}else if(Integer.parseInt(resd[i][0])==0){
}
else if(resd[i][1].equals(" day")||resd[i][1].equals(" days")){
res =res + resd[i][0]+resd[i][1] + ", " ;
}else if(resd[i][1].equals(" hour")||resd[i][1].equals(" hours")){
res=res + resd[i][0]+resd[i][1]+", " ;
}else if(resd[i][1].equals(" minute")||resd[i][1].equals(" minutes")){
res = res + resd[i][0]+resd[i][1] ;
}else if(resd[i][1].equals(" second")||resd[i][1].equals(" seconds")){
res = res +" and " + resd[i][0]+resd[i][1];
}
}
System.out.println(res);
return res;
}
网友评论