|
|
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. ok...i solved my TLE 6 and TLE 7 problems, now i think it s more than fast enough but i god WA#1 even though it gives good answers too all tests on my machine.... any ideas what s wrong ? can someone give me test 1 ? #include<iostream> #include<vector> using namespace std; int main(){
vector<char> tab; char x, previous; int size=0,j=0; while(!(cin >> x).eof()){ if(x!=previous){ tab.push_back(x); j++; previous=x; } else{ tab.pop_back(); j--; if(j>=1) previous = tab[j-1]; else previous = '!'; } } for( int i = 0; i < tab.size(); i++ ){ cout << tab[ i ]; } getchar();getchar(); } Edited by author 09.08.2011 19:27 try abhhcggcffbeedda answer must be an empty string and so it is. ... any other ideas ? i really dont know what else to do. You can't do a getchar() when the judge won't write any char! :p 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? 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. 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? just change char mas_n[200000]={0}; into char mas_n[200005]={0}; )) Edited by author 26.07.2012 18:28 #include<iostream> #include<string.h> #include<stdio.h> using namespace std; int main() { char in[200000]; int num ; char c; scanf("%c",&c); char nc = c; if(c == '\n') goto end; in[0] = c; for(num=1;;num++) { scanf("%c",&c); if(c == '\n') break; if(nc == c) { in[num-1] = '\0'; num -= 2; if((num+1) != 0) nc = in[num]; else nc = '\0';
} else { in[num] = c; nc = c; }
} end: for(int i=0;i<=num;i++) cout << in[i];
} got a 0.109s answer.. Edited by author 24.04.2013 23:52 #include <cstdio> char a[300010], k; int main(){ char c; while((c = getchar()) != EOF){ if(k == 0 || a[k - 1] != c) a[k++] = c; else k--; } for(int i = 0; i < k; i++) putchar(a[i]); return 0; } This one gives RE(AV) on the 6th test. I tried it 4 times with different sizes of array "a" (200000, 200010, 300010, 2000000) and each time got this error. I found it very strange, could you help me please? this my solution: #include <iostream> #include <string> #include <stdlib.h> #include <algorithm> using namespace std; int main(){ int bilo; string s; cin>>s; for (int j = 0; j < s.length() - 1; j++){ bilo = 0; for (int i = 0; i < s.length()-1; i++){ if (s[i] != '1') if ((s[i] == s[i+1])){ s[i] = '1'; s[i+1] = '1'; bilo = 1;
if (i < s.length()-1){ rotate(&s[i], &s[i+1], &s[i] + s.length() - i); rotate(&s[i], &s[i+1], &s[i] + s.length() - i); } } } if (bilo = 0) break; }
int i = 0; while (s[i]!='1'){ cout<<s[i]; i++; }
//system("pause"); return 0; } please send me answer on my e-mail: sergeo_91_@mail.ru or write me here. P.S. thank you in advance. I do not argue, just I want to know. Thanks. Because it can be solved using data structure called "stack". Now I got it :) Thank you very much. Stack<char> Stack = new Stack<char>(); foreach (char c in Console.ReadLine()) if (Stack.Count > 0 && Stack.Peek() == c) Stack.Pop(); else Stack.Push(c); foreach (char c in Stack.Reverse()) Console.Write(c); Because of this code. After AC i realized i used stack :) Yes, and because choosing the right data structure makes the problem solvable, and choosing the wrong one results in TLE. I had a brain blockage and couldn't think of stacks here (it's been a long time since I used them). Trying to solve using, for example, STL vector or dequeue and erase() will result in TLE on the big input cases. I realized that since very many erase() operations may be performed, delete performance is critically important, so STL list came to the rescue and got AC. Cuz' String Or a Char array is a data structure and working with data structures actually means changing adding expanding etc. them :) Hope that'll help you Use stack for those who know what stack means. For those who don't , take a look at this: n++; cin>>a[n]; if (a[n]==a[n-1]) n-=2; How input is <wwstdaadierfflitzzz>,but output <stierlitz>? This is wrong,according case 2 of this problem... Your task is to "remove from the message all pairs of identical letters" only. Ok.There are two and two <t> of the word - < stierlitz >. Ok.There are two i and two t of the word - stierlitz. The task is to undo step 3, which involves *repeatedly* inserting letter pairs. This results in more than just aabbcc... what the fuck is test#4? y don't u just post the content of those fucking tests? who can tell me,what's the sixth datas. why always WA in test 6 #include<iostream> #include<stdio.h> using namespace std; int main() {char c[200000],d; int i=0,j,k; while(cin>>c[i]&&i<200000) {char d=c[i]; if(i!=0&&c[i-1]==d){c[i]=c[i-1]=NULL;i=i-1;} else if(int(d)==32){c[i]=NULL;} else i++; } cout<<c<<endl; return 0; } Edited by author 20.07.2012 19:31 Length is 200000, not 20000 still got wa@9 please help Length is 200000, not 20000 |
|
|