Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <array>
- #include <random>
- #include <time.h>
- #include <list>
- #include <string>
- using namespace std;
- int main() {
- srand(time(NULL));
- /* part 1 */
- vector<array<int, 4> > VecArr;
- for (int i = 0; i < 1000; ++i) {
- VecArr.push_back(array<int, 4>());
- for (int j = 0; j < 4; ++j) {
- VecArr[i][j] = rand() % 10;
- }
- }
- cout << "Part 1 - all elements of VecArr got the values\n";
- /* part 2 */
- vector<int> valid;
- for (int k = 0; k < 250; ++k) {
- int s = 0;
- for (int i = k * 4; i < k * 4 + 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- if (j % 2 == 0) {
- int tmp = VecArr[i][j] * 2;
- if (tmp > 9) {
- tmp = 1 + (tmp % 10);
- }
- s += tmp;
- } else {
- s += VecArr[i][j];
- }
- }
- }
- if (s % 10 == 0) {
- cout << "Card #" << k << ' ';
- for (int i = k * 4; i < k * 4 + 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- cout << VecArr[i][j];
- }
- }
- cout << "- Ok\n";
- valid.push_back(k);
- }
- }
- for (int i = valid.size() - 1; i >= 0; --i) {
- for (int j = 3; j >= 0; --j) {
- VecArr.erase(VecArr.begin() + (valid[i] * 4) + j);
- }
- }
- cout << "\nThe number of fake cards is " << VecArr.size() / 4 << '\n';
- /* part 4 */
- VecArr.clear();
- cout << "\nPart 4 - The current size of VecArr[] equals to " << VecArr.size() << '\n';
- /* part 5 */
- list<string> ListStr1
- {"re*pr*esentative", "operati*o*n", "re*gr*et", "ex*am*ple", "lim*It*"};
- list<string> ListStr2;
- for (list<string>::iterator it = ListStr1.begin(); it != ListStr1.end(); ++it) {
- size_t b = (*it).find('*');
- (*it).erase((*it).begin(), (*it).begin() + b + 1);
- size_t e = (*it).find('*');
- (*it).erase((*it).begin() + e, (*it).end());
- ListStr2.push_back(move(*it));
- }
- for (list<string>::iterator it = ListStr2.begin(); it != ListStr2.end(); ++it) {
- cout << *it;
- }
- cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement