|
|
вернуться в форумHow to read input? I got AC at this easy problem but I'm just interested: how did you read input? I used this: for (int i=0; i<n; i++) { scanf("%d %c",&x,&ch); getline(cin,tmp); //something... } But I think it's stupid way of doing this, can someone with C++ AC show me his reading part? Edited by author 07.08.2009 18:01 Re: How to read input? char s[20]; for (int i=0; i<n; i++){ scanf("%d %s",&x,s); ... } Re: How to read input? well, this is good but i wanted something else... Is there anything in C++ which works as ReadLn in Pascal. I mean something which read and ignore characters before next newline character? I thought something like scanf("%d %c\n",&x,&ch) works but it doesn't. getline works fine but it requires to declare one more string variable and works slow. Also, can you explain me how scanf("%s",s) works? Re: How to read input? cin.ignore(maxCharsNum,delimiterChar); It ignores "maxCharsNum" symbols if there is no "delimiterChar" among them. Else it ignores all symbols before "delimiterChar" (and "delimiterChar" also). char s[N]; scanf("%s",s); Reads symbols before meet space, '\n' or '\t' and puts '\0' in the end. It doesn't stop reading if number of symbols is greater than N. So, N must be always greater than maximal number of symbols in string. Edited by author 07.08.2009 21:28 |
|
|