⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11-02-03.cpp

📁 more efftive 代码
💻 CPP
字号:
#include <iostream>#include <cmath>#include <cstring>#include <algorithm>using namespace std;bool eq_nosign(int x, int y) { return abs(x) == abs(y); }void lookup(int* first, int* last, size_t count, int val) {  cout << "Searching for a sequence of "       << count       << " '" << val << "'"       << (count != 1 ? "s: " : ":  ");  int* result = search_n(first, last, count, val);  if (result == last)    cout << "Not found" << endl;  else    cout << "Index = " << result - first << endl;}void lookup_nosign(int* first, int* last, size_t count, int val) {  cout << "Searching for a (sign-insensitive) sequence of "       << count       << " '" << val << "'"       << (count != 1 ? "s: " : ":  ");  int* result = search_n(first, last, count, val, eq_nosign);  if (result == last)    cout << "Not found" << endl;  else    cout << "Index = " << result - first << endl;}int main(){  const int N = 10;  int A[N] = {1, 2, 1, 1, 3, -3, 1, 1, 1, 1};    lookup(A, A+N, 1, 4);  lookup(A, A+N, 0, 4);  lookup(A, A+N, 1, 1);  lookup(A, A+N, 2, 1);  lookup(A, A+N, 3, 1);  lookup(A, A+N, 4, 1);  lookup(A, A+N, 1, 3);  lookup(A, A+N, 2, 3);  lookup_nosign(A, A+N, 1, 3);  lookup_nosign(A, A+N, 2, 3);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -