|
|
Страница 3 import random letters = ['a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' ,'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z'] example = 'xitsa' while len(example) < 199999: letter = random.choice(letters) point = random.randrange(0, len(example)) example = example[:point] + letter + letter + example[point:] print(example) char[200001] gives perfect time if you will check repeats while string is inputting i used deque. cout got me TLE.using printf save me. if(st.front()!=s[i]) { st.emplace_front(s[i]); } else st.pop_front();
for(it=st.end()-1; it>=st.begin(); it--) { printf("%c",*it); } i say more - it's better don't use stl-containers if it's possible. char[200001] gives perfect time // Harry Poter #include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> using namespace std; int main() { char line[200001], w2[200001]; cin.getline(line, sizeof(line)); int t = 0, i; for(i = 0; i < strlen(line); i++){ if (line[i] == line[i + 1]) { i++; A: if (line[i + 1] != line[i + 2]) { if (t != 0 && w2[t - 1] == line[i + 1]) {t--; i += 1; goto A;} } } else {w2[t++] = line[i];} } w2[t] = '\0'; printf("%s", w2); } hey if one else to know print the anser plese say me..in the test #4 i have a empty string, but the judge say me "wa" in test #4.... why??? help me please. #include <bits/stdc++.h> using namespace std; int main(){ string cad,res; cin>>cad; res = ""; int tam = cad.length(); int i,j; i=0; j=1; int boolean[tam]={0}; while(j<tam){ if(cad[i]==cad[j]){ boolean[i] = 1; boolean[j] = 1; if(i-1>=0){ i-=1; j+=1; }else{ i=j+1; j+=2; } }else{ i=j; j+=1; } } for(int i=0;i<tam;i++){ if(boolean[i]==0) res+=cad[i]; } cout<<res; return 0; } The test is "abcdeedcbaabcdeedcba"(without quotes). The answer should be ""(empty string). hey mi anwser code is the same, what is the bug I thought that stack is the best thing in this case but I've seen 0.015 and 0.001 sec . I've got 0.046 Maybe it's because of the choice of language. I use C++17 and it run in 0.001s import java.util.Scanner; import java.util.Stack; public class CliperMessage_1654_Stack { public static void main(String[] arg1) { Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); Stack<Character> stc=new Stack<>(); sb.append(sc.nextLine()); if(sb.length()<=200000){ for(int i=0;i<sb.length();i++){ if(stc.isEmpty()||(stc.peek()!=sb.charAt(i))) stc.push(sb.charAt(i)); else if((stc.peek()==sb.charAt(i))) stc.pop();
}
StringBuilder sbn=new StringBuilder(); int j=0; while(!stc.empty()) sbn.insert(j++, ""+stc.pop()); System.out.println(sbn.reverse()); } } } My code using 1 while. Time limit at test case 6? public class CliperMessage_1654 { public static void main(String[] arg0) { Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); sb.append(sc.nextLine()); if(sb.length()<=200000){ int i=0; while(i<sb.length()-1){ if((sb.charAt(i)==sb.charAt(i+1))){ sb.deleteCharAt(i); sb.deleteCharAt(i); } else if(((i>=1)&&(sb.charAt(i-1)==sb.charAt(i)))) { sb.deleteCharAt(i-1); sb.deleteCharAt(i-1); i--; }else i++; }
System.out.println(sb); } } } Can any body tell me whai is in the test case 5...??? My code seems right but everytime it says WA#5... 200000 char in test case #5!! Thanksss.. It helped me a lot... Edited by author 25.12.2015 13:35 Hello, I just had a WA in test number 6. After some research found out that my code failed at this test: 1234567ikkjji890 Mind that I used numbers instead of letters for better visibility. Accepted... public class CipherMessage1654_Accepted { public static void main(String[] args) { Stack<Character> stack = new Stack<Character>(); Scanner x = new Scanner(System.in); String s = x.nextLine(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) >= '`' && s.charAt(i) <= '9' || s.charAt(i) >= 'a' && s.charAt(i) <= 'z') { if (stack.isEmpty()) { stack.push('`'); } if (s.charAt(i) != stack.peek()) stack.push(s.charAt(i)); else stack.pop(); } } for (int i = 0; i < stack.size(); i++) { if (stack.get(i) != '`') System.out.print(stack.get(i)); } } } Edited by author 16.12.2014 09:49 import java.util.List; import java.util.ArrayList; import java.util.Scanner; public class Spion { public static void main(String[] args) { Scanner in = new Scanner(System.in); List<String>shifr = new ArrayList(); String word = in.next();
shifr.add(""+word.charAt(0));
for(int i =1;i<word.length();i++){ String s =""+word.charAt(i); shifr.add(s);
if(shifr.get(shifr.lastIndexOf(s)).equals(shifr.get(shifr.indexOf(s))) && shifr.lastIndexOf(s)==shifr.indexOf(s)+1) { shifr.remove(shifr.get(shifr.lastIndexOf(s))); shifr.remove(shifr.get(shifr.indexOf(s)));
};
}
for(String n: shifr){
System.out.print(n); }
} } what's wrong? Edited by author 28.03.2014 12:04 var text: string; flag: boolean; k, i: integer; begin readln(text); flag := true; text := text + ' '; while flag do begin k := 1; for i := 1 to length(text) - 1 do begin if (text[i + 1] = ' ') then break; if (text[i] = text[i + 1]) then begin delete(text, i, 2); k := 0; break; end; end; if k = 0 then flag := true else flag := false; end; for i := 1 to length(text) - 1 do write(text[i]); end. Edited by author 26.02.2014 01:33 Edited by author 26.02.2014 01:34 I ran countless of tests from higher tests and what I thought might be error but failed to find the issue. Anyone could provide with test data on test 7? ans is ab or ba? Describe a situation in which it could happen that the answer is "ab"? #include<stdio.h> #include<algorithm> #include<list> using namespace std; int main(){ char str[200000]; cin>>str; bool litter[26]; for(int i=0;i<26;i++) { litter[i]=false; } for(int i=0;i<strlen(str);i++) { litter[str[i]-'a']=!litter[str[i]-'a']; } list<char> clist; for(int i=0;i<strlen(str);i++) { if(litter[str[i]-'a']) { litter[str[i]-'a']=false; clist.push_back(str[i]); } } copy(clist.begin(),clist.end(),ostream_iterator<char>(cout)); return 0; } it do works on my own machine, How? input : tatu!.?.?.!utat output : "" Edited by author 20.06.2013 00:20 Edited by author 20.06.2013 00:21 Edited by author 20.06.2013 00:35 Штирлиц же "Убирает все пробелы и знаки препинания." That's a totally wrong test cases. The AC program won't give "". It is still original string. Besides there are NOT punctuation inside string. #include<iostream> #include<string.h> #include<deque> #include<stdio.h> using namespace std; int main() { string node; cin >> node; int one,two; one = 0; two = 1; int pre = 0; for(int i = 0;i < node.size();i++) { if(node[i] == '!') continue; if(node[i] == node[i+1]) { node[i] = node[i+1] = '!'; one = pre; if(i+2 < node.size()) two = i+2; while(one> 0 && two < node.size()) { while(one > 0 && node[one] == '!') one--; if(node[one] == node[two] ) { node[one] = node[two] = '!'; one--;two++; } else break; } } else pre = i; }
for(int i = 0;i < node.size();i++) { if(node[i] != '!') cout << node[i]; }
} I use stack and my solution works 0.064s :) My solution works 0.048s ;) Why your solutions is right? if input is: sddssdds then your ans is "ss"! |
|
|