Created
May 8, 2014 19:36
-
-
Save mukulrawat1986/55a9ed8d9535f441a861 to your computer and use it in GitHub Desktop.
Snippets for competitive programming for manipulating inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convert an integer to string | |
string intToString (int a){ | |
ostringstream os(a); | |
os<<a; | |
return os.str(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convet a string to a single int | |
int stringToInt(string s){ | |
int a; | |
istringstream is(s); | |
is>>a; | |
return a; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comvert a string input to a vector of int | |
// inputs like '1 3 4 5 6 7 8' | |
void stringToInt(string s, vector <int> & a){ | |
int temp; | |
istringstream is(s); | |
while(is>>temp) | |
a.push_back(temp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment