import java.util.*; public class JAVA{ public static void main(String args[]){ Scanner scanner = new Scanner(System.in); String a,w,ans="",b; while(scanner.hasNext()){ a=scanner.next(); if(a.equals("SHOW"))break; w=scanner.next(); if(a.equals("ADD")){ ans = ans+w+" "; } else if(a.equals("INSERT")){ b=scanner.next(); ans=ans.replaceFirst(b,w+" "+b); } else if(a.equals("REMOVE")){ ans=ans.replaceFirst(w+" ",""); } } System.out.println(ans); } }
第2個會錯,請問是為什麼?
第 2 測資點(49%): WA (line:1)
答案不正確
您的答案為: ASK NOT DO FOR WHAT YOUR COUNTRY CAN YOU 正確答案為: ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU
INSERT b 少空白,可能有abc誤換abcde之abc。
import java.util.*; public class JAVA{ public static void main(String args[]){ Scanner scanner = new Scanner(System.in); String a,w,ans="",b; while(scanner.hasNext()){ a=scanner.next(); if(a.equals("SHOW"))break; w=scanner.next(); if(a.equals("ADD")){ ans = ans+w+" "; } else if(a.equals("INSERT")){ b=scanner.next(); ans=ans.replaceFirst(b,w+" "+b); } else if(a.equals("REMOVE")){ ans=ans.replaceFirst(w+" ",""); } } System.out.println(ans); } }
第2個會錯,請問是為什麼?
第 2 測資點(49%): WA (line:1)
答案不正確
您的答案為: ASK NOT DO FOR WHAT YOUR COUNTRY CAN YOU 正確答案為: ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU
import java.util.*; class Ideone{ public static void main(String args[]){ Scanner scanner = new Scanner(System.in); String a,w,ans="",b; while(scanner.hasNext()){ a=scanner.next(); if(a.equals("SHOW"))break; w=scanner.next(); if(a.equals("ADD")){ ans = ans+w+" "; } else if(a.equals("INSERT")){ b=scanner.next(); ans=ans.replaceFirst(b+" ",w+" "+b+" "); } else if(a.equals("REMOVE")){ ans=ans.replaceFirst(w+" ",""); } } System.out.println(ans); } }