SlideShare a Scribd company logo
1 of 24
 
A  lil  Bit  About  Templates  B4  V  Begin So, What Are They ??? ,[object Object],[object Object],[object Object],[object Object],[object Object]
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);
-  TIP  - string s; getline(cin , s , ''); Use this to read a whole  line  of text from the input file
[object Object]
Find Simplest way to find a substring What Does It Do ? ,[object Object],[object Object],string a=“hello world”; cout<<a.find(“0 w”);
Replace An Easy Way To Replace Text In Strings What Does It Do ? ,[object Object],string a=“hello world”; cout<<a.replace(i,j,”hi”);
Other  Useful  String  Functions ,[object Object],[object Object],[object Object],[object Object],[object Object]
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;
-  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 !!!
[object Object]
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;
-  TIP  - It Is A Better Idea To Use-- getline(ss , s , ‘’); (or) s=ss.str();
 
a^=b^=a^=b; What Does It Do ?? Guesses Permitted !!
a=a^b; b=a^b; a=a^b; After  Simplifying  It  A  Little  Bit
It  Works  Coz  Of  The  Fact  That: a^b=c => b^c=a  c^a=b
[object Object]
Capabilities: Easy Sorting!! Constant Access Time!! Linear Time for finding elements!!
So why not Arrays?? Variable Size!!
Useful Functions: push_back() pop_back() insert() erase() clear() assign()
[object Object],[object Object]
C++ Already Contains:  (Used with respect to  Vector v1) sort()  stable_sort() qsort() find() reverse() merge()
There’s More.. min_element() max_element() next_permutation() prev_permutation()

More Related Content

Similar to An approach to Programming Contests with C++

Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Andrea Telatin
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
Shahjahan Samoon
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan Samoon
 

Similar to An approach to Programming Contests with C++ (20)

Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
 
3 character strings and formatted input output
3  character strings and formatted input output3  character strings and formatted input output
3 character strings and formatted input output
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
Bioinformatica: Leggere file con Perl, e introduzione alle espressioni regola...
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
Team 1
Team 1Team 1
Team 1
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
String
StringString
String
 
Qt Translations
Qt TranslationsQt Translations
Qt Translations
 
Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Ch09
Ch09Ch09
Ch09
 
2 data and c
2 data and c2 data and c
2 data and c
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
M C6java7
M C6java7M C6java7
M C6java7
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 

More from VNIT-ACM Student Chapter

More from VNIT-ACM Student Chapter (12)

An introduction to Reverse Engineering
An introduction to Reverse EngineeringAn introduction to Reverse Engineering
An introduction to Reverse Engineering
 
Introduction to the OSI 7 layer model and Data Link Layer
Introduction to the OSI 7 layer model and Data Link LayerIntroduction to the OSI 7 layer model and Data Link Layer
Introduction to the OSI 7 layer model and Data Link Layer
 
Research Opportunities in the United States
Research Opportunities in the United StatesResearch Opportunities in the United States
Research Opportunities in the United States
 
How web searching engines work
How web searching engines workHow web searching engines work
How web searching engines work
 
Research Opportunities in India & Keyword Search Over Dynamic Categorized Inf...
Research Opportunities in India & Keyword Search Over Dynamic Categorized Inf...Research Opportunities in India & Keyword Search Over Dynamic Categorized Inf...
Research Opportunities in India & Keyword Search Over Dynamic Categorized Inf...
 
Hadoop Map Reduce
Hadoop Map ReduceHadoop Map Reduce
Hadoop Map Reduce
 
Web Designing
Web DesigningWeb Designing
Web Designing
 
Inaugural Session
Inaugural SessionInaugural Session
Inaugural Session
 
Hacking - Web based attacks
Hacking - Web based attacksHacking - Web based attacks
Hacking - Web based attacks
 
Computers and Algorithms - What can they do and what can they not?
Computers and Algorithms - What can they do and what can they not?Computers and Algorithms - What can they do and what can they not?
Computers and Algorithms - What can they do and what can they not?
 
Foundations of Programming Part II
Foundations of Programming Part IIFoundations of Programming Part II
Foundations of Programming Part II
 
Foundations of Programming Part I
Foundations of Programming Part IFoundations of Programming Part I
Foundations of Programming Part I
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

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() , &quot;%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();
  • 14.  
  • 15. a^=b^=a^=b; What Does It Do ?? Guesses Permitted !!
  • 16. a=a^b; b=a^b; a=a^b; After Simplifying It A Little Bit
  • 17. It Works Coz Of The Fact That: a^b=c => b^c=a c^a=b
  • 18.
  • 19. Capabilities: Easy Sorting!! Constant Access Time!! Linear Time for finding elements!!
  • 20. So why not Arrays?? Variable Size!!
  • 21. Useful Functions: push_back() pop_back() insert() erase() clear() assign()
  • 22.
  • 23. C++ Already Contains: (Used with respect to Vector v1) sort() stable_sort() qsort() find() reverse() merge()
  • 24. There’s More.. min_element() max_element() next_permutation() prev_permutation()