|
|
back to boardCommon BoardI have 2 questions,so,if you can help...:) Hi to you! I don't know these 2 things: 1. How to read data until EOF... I tried this: while(scanf("%d",&num)!=EOF) { ... source ... }, but when i tried it (I think EOF by the keyboard is pressing CTRL+Z), my program finishes, although it had to do some operations and output on the stdout some data... So if you know how to read data untill EOF is reached, please help... 2. In PASCAL, you can read data and go to the new line with "readln"; How is it in C++? For example, you have a string with length not more than 10000000 and you read it char by char. But in any moment, you want to stop reading(prob.1102, the answer is "YES" or "NO", and if once you have found it is "NO", you don't need to read the rest of the input)and to go to the next line, to read the next string and so on.. So how to do this? If you know, please tell me this... I use the follow... I attach you a segment of a program accepted at uva.es (p.548). You must read lines of numbers(two lines are ONE test case), and you end the program when EOF is reached:). #include <iostream.h> #define EOLN '\n' . . . while ( cin >>a[0] ) //you must read at least one number or EOF { . . c = cin.get(); while ( c != EOLN ) { while ((c>'9' || c<'0') && c!=EOLN) c=cin.get(); if ( c == EOLN ) break; j = 0; do j = j*10 + (int)(c - '0'); while ((c=cin.get())<='9' && c>='0' && c!=EOLN); a[i] = j; . . i++; } n = i; for (i=0; i<n; i++) cin >> b[i]; . . cout<<min_id<<endl; //it doesn't alter the stdin } |
|
|