Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

An approach to Programming Contests with C++

2.640 visualizaciones

Publicado el

Publicado en: Educación, Tecnología
  • Sé el primero en comentar

An approach to Programming Contests with C++

  1. 2. A lil Bit About Templates B4 V Begin So, What Are They ??? <ul><li>It Aids Generic Programming </li></ul><ul><li> ( Basically, Makes Life Much Easier ) </li></ul><ul><li>You Can Create a Queue Of Type T where, T is of any type !!! </li></ul><ul><ul><li>Eg. queue<int> iq; </li></ul></ul><ul><ul><li>queue<string> sq; </li></ul></ul>
  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);
  3. 4. - TIP - string s; getline(cin , s , ' '); Use this to read a whole line of text from the input file
  4. 5. <ul><li>A world of strings </li></ul>
  5. 6. Find Simplest way to find a substring What Does It Do ? <ul><li>Returns The Index Of The First Occurrence Of The Substring. </li></ul><ul><li>If There Is No Such Occurrence, returns a value > Length Of String. </li></ul>string a=“hello world”; cout<<a.find(“0 w”);
  6. 7. Replace An Easy Way To Replace Text In Strings What Does It Do ? <ul><li>Replaces Some Particular Text In A String With The Text You Want To Replace With </li></ul>string a=“hello world”; cout<<a.replace(i,j,”hi”);
  7. 8. Other Useful String Functions <ul><li>string s=“01236789876543210”; </li></ul><ul><li>s.insert(i,”45”); </li></ul><ul><li>s.erase(i,j); </li></ul><ul><li>s.length(); </li></ul><ul><li>s.rfind(“3”); </li></ul>
  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() , &quot;%d:%d“ , &h , &m); cout<<h<<endl<<m;
  9. 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 !!!
  10. 11. <ul><li>#include<sstream> </li></ul>
  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;
  12. 13. - TIP - It Is A Better Idea To Use-- getline(ss , s , ‘ ’); (or) s=ss.str();
  13. 15. a^=b^=a^=b; What Does It Do ?? Guesses Permitted !!
  14. 16. a=a^b; b=a^b; a=a^b; After Simplifying It A Little Bit
  15. 17. It Works Coz Of The Fact That: a^b=c => b^c=a c^a=b
  16. 18. <ul><li>#include<vector> </li></ul>
  17. 19. Capabilities: Easy Sorting!! Constant Access Time!! Linear Time for finding elements!!
  18. 20. So why not Arrays?? Variable Size!!
  19. 21. Useful Functions: push_back() pop_back() insert() erase() clear() assign()
  20. 22. <ul><li>Ready to use Algorithms  </li></ul><ul><li>#include<algorithm> </li></ul>
  21. 23. C++ Already Contains: (Used with respect to Vector v1) sort() stable_sort() qsort() find() reverse() merge()
  22. 24. There’s More.. min_element() max_element() next_permutation() prev_permutation()