Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- //WOO FINAL EXAM NOTES!
- //Try to use const whenever appropriate, pass by const reference (const vector<string>&) when throwing vectors around, maybe use size_t for stuff?
- using namespace std;
- class Foo {
- public:
- Foo()
- : i{1}, names{vector<string>{"Whatever"}}{
- /*empty body*/
- }
- explicit Foo(int x)
- : i{x}{
- /*empty body*/
- }
- Foo (int x, const vector<string>& s )
- : i{x}, names{s} {
- if (i<0) {
- i = 0;
- }
- if (names.size() < 1) {
- names.push_back("whatever");
- }
- }
- void reality() {
- cout << "i = " << i << " names size: " << names.size() << endl;
- for (i : names) {
- cout << i;
- }
- cout << endl;
- }
- private:
- int i{};
- vector<string> names{};
- };
- void testFoo() {
- Foo a{};
- Foo b{3};
- Foo c{5,vector<string>{"abc","def"}};
- a.reality();
- b.reality();
- c.reality();
- vector<Foo> vf1{a,b,c};
- vector<Foo> vf2{Foo{}, Foo{1}, Foo{2, vector<string>{"aaaaylaamo","b","c"}}};
- cout << "============================" << endl;
- for (i : vf2) {
- i.reality();
- }
- }
- int main()
- {
- testFoo();
- cout << "Hello world!" << endl;
- return 0;
- }
- //Additionally, here's some loop stuff in case you forget:
- #include <iostream>
- #include <vector>
- using namespace std;
- int sumInts(vector<int> input) {
- int theSum{0};
- for (int i : input) {
- theSum = theSum+i;
- }
- return theSum;
- }
- void readInts(vector<int> &input) {
- int numOfIns{0};
- int numIn{0};
- cin >> numOfIns;
- for (int i = 0; i < numOfIns; i++ ) {
- cin >> numIn;
- input.push_back(numIn);
- }
- }
- int main() {
- vector<int> vals;
- readInts(vals);
- cout << sumInts(vals);
- }
- //and finally here's some string stuff
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- vector<string> getinput(){
- int numstrings{0};
- cin >> numstrings;
- string input{};
- vector<string> inputs{};
- int i{0};
- while (i < numstrings) {
- cin >> input;
- inputs.push_back(input);
- i++;
- }
- return inputs;
- }
- void print(string input) {
- cout << input << endl;
- }
- int testinput(string input) {
- int i{2};
- char a{};
- char b{0};
- char c{0};
- int sum{0};
- if (input.length() < 3) {
- return 0;
- }
- while (i < input.length()) {
- a = input[i-2];
- b = input[i-1];
- c = input[i];
- //cout << "a = " << a << " | b = " << b << " | c = " << c << endl;
- if (a == b && a == c) {
- i++;
- sum++;
- }
- i++;
- }
- return sum;
- }
- int main() {
- vector<string> b{getinput()};
- for (string i : b) {
- cout << testinput(i) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement