1033(13)
阿新 • • 發佈:2018-10-17
ann arr bad color har class string system.in you
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here Scanner sc=new Scanner(System.in); String bad=sc.next(); String right=sc.next(); ArrayList list=new ArrayList();//將不等於壞鍵的字符存入list當中 for (int i=0;i<right.length();i++){ for (int j=0;j<bad.length();j++){ if (right.charAt(i)==bad.charAt(j)||right.charAt(i)==bad.charAt(j)+32){ break; } else if (j==bad.length()-1){ list.add(right.charAt(i)); } } }//暫時還不能將list轉換成數組,因為這個list中元素可能因為+存在必須把大寫字母去掉 for (int i=0;i<list.size();i++){ for (int j=0;j<bad.length();j++){ if (bad.charAt(j)==‘+‘){ if ((char)list.get(i)>=‘A‘&&(char)list.get(i)<=‘Z‘){ list.remove(i); } } } } Object[] o=list.toArray(); char[] out=new char[o.length]; for (int i=0;i<o.length;i++){ out[i]=(char)o[i]; } //如果壞鍵當中存在+,那麽將out當中存在的大寫字母改成小寫,如果沒有+存在的話,直接輸出out for (int j=0;j<bad.length();j++){ if (bad.charAt(j)==‘+‘){ for (int i=0;i<out.length;i++){ if (out[i]>=‘A‘&&out[i]<=‘Z‘){ out[i]=(char)(out[i]+32); } } } } if (out.length==0){ System.out.println(); } else{ for (int i=0;i<out.length;i++){ System.out.print(out[i]); } } } }
1033(13)