zoukankan      html  css  js  c++  java
  • UVa 11849

    题目:给你两个有序序列(每一个序列中元素不同),求两序列中都出现的元素个数。

    分析:简单题。

    合并排序合并过程。

                设置两个指针。指向两序列当前元素。那个元素小指针向后移动。相同大则计数加一,同一时候后移。

    说明:简单题。(⊙_⊙)

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    
    using namespace std;
    
    int Jack[1000001];
    int Jill[1000001];
    
    int main()
    {
    	int n,m;
    	while (~scanf("%d%d",&n,&m) && n+m) {
    		for (int i = 0 ; i < n ; ++ i)
    			scanf("%d",&Jack[i]);
    		for (int i = 0 ; i < m ; ++ i)
    			scanf("%d",&Jill[i]);
    		
    		int p = 0,q = 0,same = 0;
    		while (p < n && q < m)
    			if (p < n && q < m && Jack[p] == Jill[q]) {
    				same ++;
    				p ++;
    				q ++;
    			}else if (q == m || (p < n && Jack[p] < Jill[q]))
    				p ++;
    			else if (p == n || (q < m && Jack[p] > Jill[q]))
    				q ++;
    		
    		printf("%d
    ",same);
    	} 
        return 0;
    }
    


  • 相关阅读:
    设计模式-观察者模式
    ps一寸照的编辑
    ps剪切蒙版的使用
    ps扣头发
    mysql索引优化
    ES6 $ ES5
    sping-mybatis集成
    多线程--volatile
    eclipse.exe打开是报错
    Spring Aop 详解二
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5181335.html
Copyright © 2011-2022 走看看