check this tests for "Not a floating point number" - 1 -. 1 -.e0 1 -.1e 1 #123 1 --123 1 -1.e6 1 And last one (when I fixed this, I got Accepted): -e20 1 Of course this is not an exhaustive list of possible bugs. Good luck, guys! You have to be very careful with scanf. It is wrong to write something like "scanf("%d\n", &n);" It took me a month to find this bug. You have to be very careful with scanf. It is wrong to write something like "scanf("%d\n", &n);" It took me a month to find this bug. To Samsonov Alex: why? please write answer(my mail Dembel12006@yandex.ru) Edited by author 21.01.2007 14:25Check your mail. I also have WA on test #12. Could you tell me what about scanf (cwac@hackermail.com) I have too ... wa12 i have tested all line on wrong simb.. on e>500 ... on #100... can somebody help me... de10@rambler.ru big s! Like many others I also got wa#12. Can you mail me (rddvl@mail.ru) this info about scanf? Thankful in advance. Oh, god :) I should better write it here. The thing is that if you use scanf("%d\n", &N); it reads not only number N and line break but also all whitespace characters after this linebreak. So, for example, it is possible that your program fails here: //some number 3 _1.e6//Space at the beginning of the line 3 It can say that ' 1.e6' is a correct number. Edited by author 27.02.2007 23:10 Edited by author 27.02.2007 23:10 Thanks a lot, but this situation is correctly processed in my program. But I have another question. Is number "1.e6" correct ? I'm talking about it's fractional part. According to problem's notation there shouldn't be numbers with decimal point and without fractional part. What can you say about this? Yes, it's incorrect indeed. My bug :) Thanks for info anyway. some tests: carefully check your program behavior -0.00 0 0 0.000e00000 0 0 0.00 5 0.00000 1e000000000000000000000000000000000012 3 1000000000000.000 -1e-12345678910111213141516 5 0.00000 -1.e-12 3 Not a floating point number 123.23e-12.4 0 Not a floating point number -.12e4 2 -1200.00 123.3e0 12 123.300000000000 12.2e-10 5 0.00000 12.2e+10 3 122000000000.000 12 e3 21 Not a floating point number I fixed all bugs, that i found in forum, but i still got WA on f---g test 12. Anybody! Help me! Mail: mr_ffloyd@mail.ru Edited by author 16.04.2007 19:19 Power can be vary big: as positive as negative! But "It is guaranteed that a length of a result will not exceed 200 symbols." Very good test: 0.0e+1212121332233333333 2 # 0e1212121332233333333 2 # answer: 0.00 =) PS: thank you, PieceOfMeat ! Good test! You have helped me! Edited by author 08.01.2012 05:41 Edited by author 08.01.2012 05:41 I used cin >> N; gets(s); instead of scanf("%d\n", &N); and got AC :) Also, -0.0000010e+6 0 -1 (got me on test 12 and isn't mentioned here) Maybe someone has already written about it, but I didn't find. !!--BE CAREFUL:--!! Test 12 is correct, it has big exponent part like 2E100000000000 10 and answer would look like 0.00..000 the right answer should be 2<many zeros>.<10 zeros> but as it's granted that the output will not exceed 200 symbols, i don't think there will happen to be such inputs. or the maximum output can be a too long to deal with. >>Posted by SkorKNURE October 23, 2008 08:40 >> >>Maybe someone has already written about it, but I didn't >>find. >> >>!!--BE CAREFUL:--!! >> >>Test 12 is correct, it has big exponent part like >>2E100000000000 >>10 >> >>and answer would look like >>0.00..000 Edited by author 20.05.2009 21:33 I had a stupid error... test: 12. 2 # my program`s output was 12.00, should be NAN. You can use BigDecimal constructor for checking the validity of number. After some preprocessing to the realnumber String. Good luck. It is not clear if empty lines can be used in the input. Is the next example possible? <empty line> 5 # Yes it possible. A length of the string S doesn't exceed 100 symbols, but it not guaranteed not to be empty. Extra hint for you: try this: -7293874219874982174982174987321E-18446744073709551616 10 # Thank you, AterLux. That test is OK. I tried other tests from the forum. They are OK too. Anyway I have WA12. Moreover, is the next example with just 2 lines possible? # 1 It seems that it's possible. Do we have to write "Not a floating point number" because according to the statement we need to answer on each pair lines of the input? That's hair-splitting # means end of input, you need not to process this pair, also you need not to read second line in this pair. My both AC solution (Pascal & Java) will not output anything with your example. But, as we know, 12th test is not empty. When you get "Crash (Access violation)" - in most cases it mean reading or writing out of array bounds - so check it sizes. check you can process 100-character string and can output 200-character at line Be carefull with greatest numbers, + and - before numbers (and exponent too!), check "Nafpn" answer for double -- or ++ or -+ and so on also check you output 0.000 (without minus) when trimming -0.0000xxxx. It is clear that we can't have leading spaces in case correct real number. But is it possible to have spaces after correct number till the end of the string? Example: 1.2e-3SSS 5 # No. Trailing as leading spaces not satisfy the syntactical description. It states in the problem that the input stops by 2 lines. First one is "#\n", but what is in the second line of input termination? Is there any number N or it can be just CR? try this: -7293874219874982174982174987321E-18446744073709551616 10 # expected to be 0.0000000000 Hi everyone! I had WA#12 for quite a long time, even after I had tried all the tests listed here. I finally got AC after I checked the input for space characters (isspace). After that I hardcoded a check for ' ', '\n', '\r', '\t', '\v', '\f', '\a', '\b', (and removed the isspace) and it gave me WA. In the C standart isspace gives true only for space, newline (\n), carrige return (\r), horizontal tab (\t), vertical tab (\v), form feed (\f) AND others depending on the locale... I cannot understand what kind of symbols they have put in this test case because my program doesn't allow any whitespace at all (I handle each character one by one, and I look for perfect match for isdigit, '+', '-', '\0', 'e', 'E', so I just cant miss a space character) I suggest review of this test case and removing any fancy characters found in it. If someone wants to see my solution email me iskren [dot] chernev [at] gmail [dot] com You are right. It's a very strange test case. I couldn't pass without isspace(). There can not be any spaces or other stuff in the line? If there some simbol except { 0123456789+-.eE } I must print not floating point number. Am I right? Btw, I use gets() to read lines... Passed all test form the board however WA 12... I had the same problem. I start to think that std::string works not correct with such simbols. Thanks a lot. You are not right, guys. There is nothing special in 12 test as regards symbolic input. The trouble is in incorrect algorithm - only after I've found serious bug in my prog it easily got AC. really trouble in isdigit() if you add such code: for (int i = 0; i < 256; i++) { char c = i; //cout << i << endl; if (isdigit(c) && ((i > '9') || (i < '0'))) cout << i << endl; } you will get a WA1. it's trouble with intel c++ as aI understand. My first guess was wrong about srd::string Vedernikoff Sergey: I think you didn't use isdigit in your code. Edited by author 04.07.2008 19:45 Edited by author 04.07.2008 19:45 if you wrote your own isdigit can hehp you. for example such code: bool isdigit(char c) { return c >= '0' && c <= '9'; } > (i > '9') || (i < '0') you exclude nine and zero var x:real;s,s1:string; c,n:integer; begin repeat readln(s); val(s,x,c); if s='#' then halt; readln(s1); if c=0 then begin val(s1,n,c);writeln(x:0:n) end else writeln('Not a floating point number'); until s1='#'; end. Edited by author 22.03.2011 16:49 Edited by author 22.03.2011 16:49 1) the exponent may be very large (absolute value). e.g. -100000000000000000000000000000000000. 2) the exponent may pretend to be very large, but actually not. e.g. 000000000000000000000000000000000010 3) 12.e1 is not a valid floating point number, because the dot cannot be the last character of the integral part according to the grammar mentioned. good luck try also tests such as --1 1 I used conversion String to BigDecimal in Java. But cases 1 and 3 (in Koala's message) should be processed separately. To process very large negative exponent I used the following String res; try { res = bd.toPlainString(); } catch (OutOfMemoryError e) { // gets here if exp < -1000000 res = "0.0"; // no need to keep any digits if exp < -200 } But I don't like it. And maybe it's wrong? Nevertheless I still have WA 12 :))) Edited by author 02.06.2010 13:54 why WA? Edited by author 08.04.2010 14:57 I've check all the data here..but i still get WA#12.. #include <iostream> #include <cstring> #include <string> #define inf 214748364 using namespace std; struct tmono { int n[9000]; int w,nega,xs; }; char s[1000]; int xs,len,con,e; tmono num; string res; inline bool isnum(char ch) { return '0'<=ch&&ch<='9'; } inline bool getnum(int st,int en,tmono &e) { memset(e.n,0,sizeof(e.n)); e.w=0;e.xs=0;e.nega=0; if(s[st]=='-') e.nega=1,++st; else if(s[st]=='+') e.nega=0,++st; /* while(s[st]=='+'||s[st]=='-') { if(s[st]=='-') e.nega=!e.nega; ++st; } */ for(int i=en;i>=st;i--) if(s[i]=='.') { e.xs=en-i; for(int j=i;j<en;j++) s[j]=s[j+1]; --en; break; } for(int i=st;i<=en;i++) if(!isnum(s[i])) return 0; e.w=0; for(int i=en;i>=st;i--) e.n[++e.w]=s[i]-'0'; return 1; } inline bool work() { res=""; cin>>xs; int tempxs=xs; scanf("\n"); if(s[0]=='.') { for(int i=len-1;i>=0;i--) s[i+1]=s[i]; s[0]='0'; len++; } if(!isnum(s[0])&&s[0]!='-'&&s[0]!='+') return 0; con=0; for(int i=0;i<len;i++) { if(s[i]=='e'||s[i]=='E') { if(con!=0) return 0; con=i; } if(s[i]!='e'&&s[i]!='E'&&s[i]!='-'&&s[i]!='+' &&s[i]!='.'&&!isnum(s[i])) return 0; if(s[i]=='.'&&!isnum(s[i+1])) return 0; } e=0; bool enega=0; if(con!=0) { e=-inf; int j=con; con++; if(s[con]=='+'||s[con]=='-') { if(s[con]=='-') enega=!enega; con++; } /* while(s[con]=='-'||s[con]=='+') { if(s[con]=='-') enega=!enega; ++con; }*/ for(int i=con;i<len;i++) { if(!isnum(s[i])) return 0; if(e==-inf) e=0; e=e*10+s[i]-'0'; if(e>500) break; } if(e==-inf) return 0; if(enega) e*=-1; len=j; } --len; if(!getnum(0,len,num)) return 0; num.xs-=e; while(num.n[num.w]==0&&num.w>0) --num.w; bool isxs=0; if(num.xs<=0) { for(int i=num.w;i>=1;i--) res+=num.n[i]+'0'; while(num.xs<0) { res+="0"; num.xs++; } }else { int j=max(num.w,num.xs); if(num.xs>num.w) { num.w=num.xs; num.xs=0; res+="0."; isxs=1; } for(int i=j;i>=1;i--) { if(i==num.xs) isxs=1; if(isxs&&xs==0) break; if(i==num.xs) res+="."; if(isxs)--xs; res+=num.n[i]+'0'; } } while(xs>0) { if(!isxs) res+=".",isxs=1; res+="0",--xs; } while(res[0]=='0') res.erase(0,1); if(res.length()==0) res.insert(0,"0"); if(res[0]=='.') res.insert(0,"0"); for(int i=0;i<res.length();i++) if(res[i]=='.') if(res.length()-i<tempxs) { tempxs-=res.length()-i; while(tempxs--) res.insert(res.length()-1,"0"); }else res.erase(i+tempxs,res.length()-i-tempxs-1); if(res[res.length()-1]=='.') res.erase(res.length()-1,1);
if(num.nega) for(int i=0;i<res.length();i++) if('1'<=res[i]&&res[i]<='9') { res.insert(0,"-"); break; } for(int i=1;i<res.length();i++) if(res[i]=='.'&&!isnum(res[i-1])) { res.insert(i,"0"); break; } if(res[res.length()-1]=='.') res.erase(res.length()-1,1);
res+="\n"; return 1; } inline void reads() { memset(s,0,sizeof(s)); gets(s); len=strlen(s); while(len>=1&&isspace(s[len-1])) s[len]=0,--len; while(isspace(s[0])) { for(int j=0;j<len-1;j++) s[j]=s[j+1]; s[len]=0;len--; } } int main() { #ifndef ONLINE_JUDGE freopen("input.in","r",stdin); freopen("output.out","w",stdout); #endif reads(); while(!(strlen(s)==1&&s[0]=='#')) { if(!work()) printf("Not a floating point number\n"); else cout<<res; reads(); } return 0; } Check that: S12.0 2 # where S is a space (" "). My AC program says that its not a correct number because of leading space. "For each pair of lines your program should write to an output a message: "Not a floating point number", if the string S is not a correct <real number>..." <real number> does not contain spaces. =) Good luck! Many thanks!!!really a helpful suggest! now I got AC. thanks again! Edited by author 23.03.2010 05:23 NOT FLOATING FOR 1)1E2.1 2)2E2+1 3)2E2-1 4)E 5)-+3 6)3EE ----------------------------------------- 1) 1E1 1 10.0 1E+1 1 10.0 0E10 1 0.0 0 1 0.0 000.1 1 0.1 0.1E1 0 1 why"-+3" isn't a correct number.? I got Crash on Test #12...I don't know why. My e-mail: xiaomengxian@gmail.com Please send sth to my e-mail if it is not convienent to say here. Thanx. I tried with Scanner and BufferedReader, but have no luck :( Help???? So... how to input it in Java? Thanks for support, but no one answers!!!! :D Ask Donny, he knows the answer!!!! In this problem you need to parse the string, so I think you need to do it char by char. I used BufferedReader.readLine, and then parsed the aquired string... I tried using a StringReader created out of the string, and then used it's read() method to get chars out of it, but you could also read the chars directly from the string (charAt(int)), or you could dump it into an char array. The first test is the sample test (I'm pretty sure). Note that -0.051 gets printed as 0.0 withouth a minus sign in front. Look at first http://acm.timus.ru/help.aspx?topic=javaScanner in = new Scanner(System.in); And use method of this object,(for example) int x = in.nextInt(); long x = in.nextLong(); String st = in.nextLine(); and etc. Well ... My solution gives the right answer for the sample test case , for all forum test cases, and for test cases [1,11]. But, Wrong Answer #12 :S. What's the trick.. ?! Every test case I test on my solution works fine for me. Does anyone know some more tricky test cases??? May I say "Yo Brother"? :D I have the same problem. Hope somebody give us answers . . . . why 10 0.0 -0.0 1100000000000000000000000000000.0000000000 -0.0 24680976.32135864232426891300 Not a floating point number Not a floating point number is incorrect output for the sample (test#1)? Edited by author 24.10.2008 23:22 'cause you can't write -0.0 I've never seen something like that. Maybe you have? |
|