寻找两个升序数组里的共同值
来源:互联网 发布:淘宝上匡威正品店 编辑:程序博客网 时间:2024/06/03 16:01
// MicrosoftInterviewProblem.cpp : Defines the entry point for the console application.//两个含有n个元素的有序(非降序)整型数组a和b(数组a与b中都没有重复元素),求出其共同元素,//a = 0, 1, 2, 3, 4//b = 1, 3, 5, 7, 9//那么它们的交集为{ 1, 3 }。#include "stdafx.h"#include <iostream>#include <stdlib.h>#include <vector>using namespace std;void FindTheSame(vector<int>&a, vector<int>&b, vector<int>&c){ int asize = a.size(); int bsize = b.size(); int aptr, bptr; aptr = bptr = 0; while (aptr < asize&&bptr < bsize) { if (a[aptr] == b[bptr]) { c.push_back(a[aptr]); aptr++; bptr++; } else if (a[aptr] < b[bptr]) aptr++; else bptr++; }}int main(){ vector<int>a; vector<int>b; vector<int>c; int temp; cout << "please input the vector a and b in no decrease sequence! -1 stop the input" << endl; cout << "a: "; while (1) { cin >> temp; if (temp == -1) break; a.push_back(temp); } cout << "b: "; while (1) { cin >> temp; if (temp == -1) break; b.push_back(temp); } FindTheSame(a, b, c); cout << "The same is : " ; for (auto it = c.begin(); it != c.end(); it++) cout << " " << *it; system("pause"); return 0;}
2 0
- 寻找两个升序数组里的共同值
- 两个升序数组的中位数
- 第十四题(升序数组中寻找和为特定数的两个元素)
- 找出升序数组中和为给定值的两个数字
- 找出升序数组中和为给定值的两个数字
- 找出升序数组中和为给定值的两个数字
- 找出升序数组中和为给定值的两个数字
- 将数组里的成员升序排列
- 寻找二叉树两个结点的最低共同父节点
- 寻找两个数组的中位数
- 寻找三个有序数组的共同最小元素
- 查找两个排序数组的中间值--以升序数组为例
- 把两个排好序的数组,升序插入到另一个数组
- 求两个长度相同的升序数组的中位数
- 数组------寻找和为定值的两个数
- 在升序数组中查找和等于给定值的两个数
- 【剑指offer】【41】找出升序数组中和为给定值的两个数字
- 求两个升序数组的交集、并集、补集
- 浅谈Javascript事件委托(代理)
- New package not yet registered with the system.
- python - 类 class
- Java核心---集合类
- Lua UnPack函数用法
- 寻找两个升序数组里的共同值
- UILabel属性, AttributedString字符串属性 (从网络搜集整理)
- LeetCodeOJ_231_Power of Two
- 黑马程序员——基础知识——正则及常见类
- 常用iOS、Mac框架和库及常用中文开发博客
- edditText正则限制特殊符号输入
- 鸟哥的Linux私房菜.基础学习篇(第三版)——互动出版网
- InputManager 的启动过程
- ListView 选中条目样式改变