Last active
April 3, 2016 20:16
-
-
Save mgarg1/f7ebbf622475f7a810e1 to your computer and use it in GitHub Desktop.
Important Cpp snipets
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
//using next permutation | |
while(next_permutation(vec.begin(), vec.end()) ){ | |
// do some processing on vec | |
} | |
//using sort | |
std::sort (myvector.begin(), myvector.begin()+4) | |
std::sort (myvector.begin(), myvector.end()) | |
//intialise vector with another array | |
static const int arr[] = {16,2,77,29}; | |
vector<int> vec (arr, arr + sizeof(arr) / sizeof(arr[0]) ); | |
//making a pair | |
std::pair <int,int> foo,bar; | |
foo = std::make_pair (10,20); | |
bar = std::make_pair (10.5,'A'); | |
//get the index of iterator | |
it - vec.begin() | |
std::distance(vec.begin(), it) | |
//sort with storing indices | |
typedef std::pair<int,int> mypair; | |
/*store index,value in mypair and sort with given function*/ | |
bool comparator ( const mypair& l, const mypair& r) | |
{ return l.first < r.first; } | |
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
int main() | |
{ | |
string st,str1; | |
getline(cin,st); | |
istringstream ss(st); | |
while(ss>>str1){ | |
cout<<str1<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment