|
|
вернуться в форумTime limit exceeded on tes 8 (java), i dont know which way is excellent Послано Aydar 15 авг 2011 12:54 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Iterator; import java.util.Stack; public class problem1654 { public static void main(String[] args) throws IOException { BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); String str=inp.readLine(); Stack<Character> st=new Stack<Character>(); st.push(str.charAt(0)); String s=""; for(int i=1;i<str.length();i++){ if(!st.empty()&&st.peek()==str.charAt(i)) st.pop(); else{ st.push(str.charAt(i));
} }
while(!st.empty()){ s=s+st.pop(); } int n=s.length(); for(int i=0;i<n;i++){ System.out.print(s.charAt(n-i-1));
} }} Re: Time limit exceeded on tes 8 (java), i dont know which way is excellent Послано Abzal 22 авг 2011 19:23 When i used stack(from STL) in C++, i'd got TL8. But after i realzed stack by using array, i got AC Re: Time limit exceeded on tes 8 (java), i dont know which way is excellent Don't use : while(!st.empty()){ s=s+st.pop(); } -------- Use this phrase at the end of your Code: Iterator<Character> b = st.iterator(); while(b.hasNext()){ System.out.print(b.next()); } Re: Time limit exceeded on tes 8 (java), i dont know which way is excellent Послано jim 21 мар 2018 06:11 your reply help me very much!3Q |
|
|