|
|
Страница 8 I've got several times WA 10 and in the forum I couldn't find any test for this test, and finally I found where was the mistake. Try this: (* WTF?!! * ) answer is yes No! It's wrong. The asnwer is NO because the comment isn't closed. The comment should end by '*)', not '*\n)' Test: ((**)*) My answer is YES, but if we delete comment (**) it will remain only (*) and it must be arithmetic expr, but it's not cuz arithmetic expressions can't start with (*, so the right answer is NO, am I wrong? You are wrong. There are no rules for comments if there are no comments. lol char s[16384] ; unsigned n = 0; // AC 0.001s with this code. for(int c = std::getc(stdin); c != EOF; c = std::getc(stdin)) s[n++] = c; // and AC 0.015s with n = fread(s,1,sizeof(s)-1,stdin); code. // I'm wonder that the std::getc faster than fread!! [deleted] P.S. Don't EVER forget to initialize your variables. Edited by author 30.01.2015 01:18 Edited by author 30.01.2015 01:19 Страница 7 I use "string ch" AC,but " char ch[maxn]" WA4,I don't know why ..... You may be forgetting that C strings contain ONE more character that is called terminal character (or whatever). So it must be 10001. And it works! for me Note*: if you have WA1 just skip all #10 and #13 symbols from input data! ((*Answer is YES*)) (((*Answer is YES*))) (**) YES (* NO (*) NO (*(*) YES (11(*)) NO (*(**)*) NO ((**)*)(**)*) NO! ((**)*) YES ()() (()) ((())) YES (1+1 ) YES THANK YOU very much for "(*(*) YES"! Can anybody tell what the problem ? Edited by author 30.12.2012 19:51 I think my program is correct. Who can tell me why I got wa? #include<cstdio> #include<cstdlib> #include<cstring> char a[100005],b[100000]; char cs[]="=+-*/0123456789)("; bool pd(char ch){ for(int i=0;i<17;i++) if(ch==cs[i]) return 1; return 0; } int main(){ while(gets(b)){ strcat(a,b); } int len=strlen(a); int ha=0,k=0; for(int i=0;i<len;i++){ if(ha){ if(a[i]=='*' && a[i+1]==')') ha=0; }else{ if(a[i]=='*' && a[i-1]=='(') ha=1; else{ if(k>0 && (!pd(a[i]))){ printf("NO"); return 0; } if(a[i]=='(') k++; if(a[i]==')') k--; if(k<0) { printf("NO"); return 0;} } } } if(ha || k!=0) { printf("NO"); return 0; } else printf("YES"); system("pause"); return 0; } If you have WA1 just skip all #10 and #13 symbols from input data! You may not still be in a comment when you finish reading all input. Hey, everybody! I'd like to ask for a test data of this problem similar to test #8. I've read through the discussions and passed all the test data given in earlier topics but still got stuck at #8. Any help will be appreciated!! Edited by author 07.04.2012 14:05 I've figured out the problem! It seems that I'm not familiar with the 'feof' function's action. In fact earlier discussions mentioned it but since the vim editor appends a newline in the end of my test input file I was unable to notice this. May this be of any help for those who meet the same problem. Is there any link where I can access\download the input test vectors for problem "1027. D++ Again" ? -Hari use state machine with char-by-char reading. We know last char and last state, so we can find next state. Brackets should be counting during reading. If we have '(', so we plus 1, ')' - minus 1. If brackets < 0 and state is some of arifmetic state - it's error. New tricky test was added, and all AC submissions were rejudged. 96 authors lost AC. why test#26 ... what mean? I use this and get AC: char str[30010]; int strsize = 0; while (fgets(str + strsize, 20000, stdin)) strsize = strlen(str) - 1; ++strsize; do not save newlines! make if to skip them for example: cin >> noskipws; while(cin >> ch) { if (ch != '\n') s[n++] = ch } This is my code: #include <stdio.h> #include <string.h> #define ulong unsigned long void main() { #ifndef ONLINE_JUDGE freopen("in.txt","rt",stdin); freopen("out.txt","wt",stdout); #endif bool comment=0,arithmetical=0; long brakets=0; char syms[10001]; ulong i=0; while(fgets(syms+i,10000,stdin)) { i=strlen(syms)-1; } for(i=0;i<strlen(syms);++i) { if(comment) { for(;i<strlen(syms);++i) if(syms[i]=='*'&&syms[i+1]==')') { ++i; comment=0; break; } continue; } if(arithmetical) { for(;i<strlen(syms);++i) { if(!((syms[i]>=0x28&&syms[i]<=0x2B)||(syms[i]>=0x30&&syms[i]<=0x39)||syms[i]=='-'||syms[i]=='/'||syms[i]=='=')) { printf("NO"); return; } if(syms[i]=='(') { if(syms[i+1]=='*') { ++i; comment=1; break; } ++brakets; } if(syms[i]==')') { --brakets; if(!brakets) { arithmetical=0; break; } } } continue; } for(;i<strlen(syms);++i) { if(syms[i]=='(') { if(syms[i+1]=='*') { ++i; comment=1; break; } ++brakets; arithmetical=1; break; } if(syms[i]==')') { printf("NO"); return; } } } if(comment||arithmetical) { printf("NO"); return; } printf("YES"); } why wa 26? (*(**)*) must be "YES" or "NO"? must be "NO". i find the mistake.it seems, test contains the limit of text in one line. Edited by author 25.06.2011 17:34 Edited by author 25.06.2011 17:35 This is my code: #include <stdio.h> #define ulong unsigned long void main() { #ifndef ONLINE_JUDGE freopen("in.txt","rt",stdin); freopen("out.txt","wt",stdout); #endif bool comment=0,arithmetical=0; long brakets=0; char syms[10001]; ulong i; while(!feof(stdin)) { gets(syms); i=0; while(syms[i]) { if(comment) { while(syms[i]) { if(syms[i]=='*') { ++i; if(syms[i]==')') { ++i; comment=0; break; } } ++i; } } if(arithmetical) { while(syms[i]) { if(!((syms[i]>=0x28&&syms[i]<=0x2B)||(syms[i]>=0x30&&syms[i]<=0x39)||syms[i]=='-'||syms[i]=='/'||syms[i]=='\n'||syms[i]=='=')) { printf("NO"); return; } if(syms[i]=='(') { ++i; if(syms[i]=='*') { ++i; comment=1; break; } ++brakets; continue; } if(syms[i]==')') { ++i; --brakets; if(!brakets) { arithmetical=0; break; } } ++i; } continue; } while(syms[i]) { if(syms[i]=='(') { ++i; if(syms[i]=='*') { ++i; comment=1; break; } arithmetical=1; ++brakets; break; } if(syms[i]==')') { printf("NO"); return; } ++i; } } } if(arithmetical||comment) { printf("NO"); return; } printf("YES"); } WHY WA1?! Give me solution for this task, please, i don't understand why i get WA#1 Страницы: 8 7 6 5 4 3 2 1 Предыдущая |
|
|