Skip to content

Instantly share code, notes, and snippets.

@nastacio
Last active July 10, 2025 16:26
Show Gist options
  • Select an option

  • Save nastacio/62dcb7a483fab2789450fbd298850448 to your computer and use it in GitHub Desktop.

Select an option

Save nastacio/62dcb7a483fab2789450fbd298850448 to your computer and use it in GitHub Desktop.
cpp-notes.txt
# parse input
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
vector<int> parseInts(string str) {
vector<int> *result = new vector<int>();
stringstream ss(str);
char ch;
int value;
while (! ss.eof()) {
ss >> value >> ch;
result->push_back(value);
}
return *result;
}
int main() {
string str;
cin >> str;
vector<int> integers = parseInts(str);
for(int i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return 0;
}
#
# String processing
#
#include <iostream>
#include <string>
using namespace std;
int main() {
string a;
string b;
cin >> a;
cin >> b;
int lena = a.size();
int lenb = b.size();
string ab = a + b;
string aprime = b[0] + a.substr(1, lena-1);
string bprime = a[0] + b.substr(1, lenb-1);
cout << lena << ' ' << lenb << std::endl;
cout << ab << std::endl;
cout << aprime << ' ' << bprime << std::endl;
return 0;
}
class Box {
int l;
int b;
int h;
public:
Box() {
l = b = h = 0;
}
Box(int linput, int binput, int hinput) {
l = linput;
b = binput;
h = hinput;
}
Box(Box &bxinput) {
l = bxinput.l;
b = bxinput.b;
h = bxinput.h;
}
int getLength() {
return l;
}
int getBreadth () {
return b;
}
int getHeight () {
return h;
}
long long CalculateVolume() {
return static_cast<long long>(l)*b*h;
}
//Overload operator < as specified
bool operator<(Box& b) {
bool result =
this->l < b.l ||
(this->b < b.b && this->l == b.l) ||
(this->h < b.h && this->b == b.b && this->l == b.l);
return result;
}
// Friend function to overload <<
friend std::ostream& operator<<(std::ostream& out, const Box& B);
};
// Overload << operator outside class
std::ostream& operator<<(std::ostream& out, const Box& B) {
out << B.l << ' ' << B.b << ' ' << B.h;
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment