|
|
back to boardHow Correctly read data??(C++) There is nothing else in the file, except maybe for some extra spaces or line breaks. What das it mean? Maybe? #input 1 4 000 000 -------- OR #input 2 6 000 00 111111 000111 Who solve this problem please tell how read input. I use i=scanf("%s",str1); if(i==EOF){ size=1; return ; } //while size >1 But always get WA1. Sorry for my English. Re: How Correctly read data??(C++) PART of my AC source: ===================== char *in; void delete_spaces (void) { int i; for (i = 0; isdigit(in[i]); i++); in[i] = 0; } int main (void) { scanf ("%i", &N); in = new char[N + 2]; gets (in); while (gets (in)) { delete_spaces (); // decoding... outputting... } return 0; } Re: How Correctly read data??(C++) PART of my AC source: int main( void ) { scanf("%d", &N); while (scanf("%s", S) == 1) { ... } return 0; } PS: I write using C but C++ also compile it. i don't understand. I am really depressed. scanf("%d",&N); while (scanf("%s", str) == 1) { delete_spaces (); correct(); out(); } ALWAYS get WA1. and printf("0000\n0110\n1001\n1111\n"); return 0; too incorrect Who has test №1? Please give. lifanov@mail.ru Re: i don't understand. Maybe first test is not the same as in sample input... Maybe something wrong with your decoding function? Edited by author 02.04.2005 19:27 Re: i don't understand. input string: 001 1 000 111 if you use scanf("%s",&str); str="001" if you use gets(str); str="001 1 000 111" So... ;) I think this: ... int n,i,j; char t[1000],word[1000]; scanf("%i",&n); gets(t); while (!feof(stdin)) {gets(t); j=0; for (i=0;i<strlen(t);i++) if (isdigit(t[i])!=0) {word[j]=t[i]; j++;} word[j]='\x0'; ... } ... would be OK Re: How Correctly read data??(C++) Posted by Apiwat 31 Dec 2006 21:40 i'm confusing with your "delete_spaces" function. void delete_spaces (void) { int i; for (i = 0; isdigit(in[i]); i++); in[i] = 0; } All i got from this source is... "change the 1st ' ' from the left into '0'." & "if ' ' is not found in the line -> add '0' to the right." So, I don't think "delete_spaces" is a correct function. |
|
|