Making communications land - Are they received and understood as intended? we...
An approach to Programming Contests with C++
1.
2.
3. File Handling Handling Input, Output From Files Is Much Easier Than You Think !!! freopen(“input file name”,”r”,stdin); freopen(“output file name”,”w”,stdout);
4. - TIP - string s; getline(cin , s , ''); Use this to read a whole line of text from the input file
5.
6.
7.
8.
9. Extract Data From A String With sscanf() It is like scanf() but, scans from a string instead of standard input !!! string s=“12:40”; int h,m; sscanf(s.c_str() , "%d:%d“ , &h , &m); cout<<h<<endl<<m;
10. - TIP - You can use find and replace together, to replace all occurences of a particular substring in a string, with some other sequence of characters, irrespective of the size of the new sequence of characters ! Very Useful !!!
11.
12. Converting Anything Printable, To A String Not as hard as it sounds !! stringstream ss; string s; float f=1.732; int i=43; char c=‘g’; ss<<“StringstreamsRock!!”<<f<<i<<c; ss>>s; cout<<s;
13. - TIP - It Is A Better Idea To Use-- getline(ss , s , ‘’); (or) s=ss.str();