#include <iostream>#include <list>#include <map>#include <queue>#include <stack>#include <string>#include <vector>#include "singleton.hpp"#include "sort.hpp"class Point {public:Point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}virtual void printf() {std::cout << x << "," << y << ", " << z << std::endl;}virtual void printf(int a) { std::cout << "a: " << a << std::endl; }int printf(std::string str) {std::cout << "str: " << str << std::endl;return 1;}protected:int x, y, z;};class Point2D : public Point {public:Point2D(int x = 0, int y = 0, int z = 0) : Point(x, y, z) {}public:// void printf() {// std::cout << "Point2D: " << x << "," << y << ", " << z << std::endl;// }//// void printf(int a) {// std::cout << "Point2D: a: " << a << std::endl;// }int printf(std::string str) {std::cout << "Point2D str: " << str << std::endl;return 1;}};std::vector<int> uniqueByMap(const std::vector<int> &v) {std::vector<int> result;std::map<int, int> nums;for (const auto item : v) {nums[item]++;}for (const auto num : nums) {if (num.second == 1) {result.push_back(num.first);}}return result;}std::vector<int> unique(const std::vector<int> &v) {std::vector<int> result;int n = v.size();if (n == 0) return result;int slow = 0, fast = 1;while (fast < n) {if (v[fast] != v[slow]) {if ((fast - slow) == 1) result.push_back(v[slow]);slow = fast;}fast++;}if (v[n - 1] != v[n - 2]) {result.push_back(v[n - 1]);}return result;}int main() {// {// Point p;// Point2D p2d;//// Point *pp = &p2d;// pp->printf();// pp->printf("string by Point pointer");//// Point2D *pp2d = &p2d;// pp2d->printf("string by Point2D Pointer");// p2d.printf("string by Point2D object");// p.printf("string by Point object");//// p2d.printf();//// p2d.printf(1);// }//// {// using namespace single;// Singleton * s1 = Singleton::Instence();// Singleton * s2 = Singleton::Instence();// s1->test();// s2->test();//// }//// {// std::string str = "hello world Http";////// }//// {// std::queue<int, std::list<int>> q;// for(int i = 0; i < 10; ++i) {// q.push(i);// }// q.front();// q.back();// q.pop();// q.size();//// }sort::testFindExceptionNum();// {// std::vector<std::vector<int> > ex = {{1, 2, 2, 3, 4, 4, 6},// {1, 1, 2, 2, 3, 4, 4},// {1, 2, 3, 4, 5, 6},// {1, 1, 1},// {1, 2, 2}};// for (const auto exItem : ex) {// std::vector<int> result = unique(exItem);// for (const auto i : result) {// std::cout << i << " ";// }// std::cout << "\n";// }// }return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。