zoukankan      html  css  js  c++  java
  • 小米笔试题

    题一:

    题解:

    #include <iostream>
    #include <sstream>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <deque>
    #include <queue>
    #include <map> 
    
    using namespace std;
    
    
    bool jiaocha(const vector<int> &vec1, const vector<int> &vec2)
    {
    	for(auto it = vec2.begin(); it != vec2.end(); ++it) {
    		if(find(vec1.begin(), vec1.end(), *it) != vec1.end()) {
    			return true;
    		}
    	}
    	return false;
    }
    
    void merge(vector<int> &vec1, vector<int> &vec2)
    {
    	for(auto it = vec2.begin(); it != vec2.end(); ++it) {
    		if(find(vec1.begin(), vec1.end(), *it) == vec1.end()) {
    			vec1.push_back(*it);
    		}
    	}
    }
    
    int main()
    {
        int n, num;
    	string s;
    	cin >> n;
    	getline(cin, s);
    	vector<vector<int>> vec(n);
    	for(auto row = vec.begin(); row != vec.end(); ++row) {
    		getline(cin, s);		
    		istringstream ss(s);
    		while(ss >> num) {
    			row->push_back(num);
    		}
    	} 
    	
    	for(auto row = vec.begin(); row != vec.end(); ++row) {
    		for(auto row2 = vec.begin(); row2 != vec.end(); ++row2) {
    			if(row == row2)	continue;
    			bool bf = jiaocha(*row, *row2);
    			if(bf) {
    				merge(*row, *row2);
    				row2 = vec.erase(row2);
    				--row2;
    			}
    		}
    	}
    	
    	int maxlen = 0;
    	for(auto row = vec.begin(); row != vec.end(); ++row) {
    		if(row->size() > maxlen) {
    			maxlen = row->size();
    		}
    	}
    	cout << vec.size() << endl << maxlen << endl;
        return 0;
    }
    

      

  • 相关阅读:
    openwrt 更改 debug 等级(hostapd)
    openwrt 中procd
    openwrt增加串口登录需要密码
    openwrt设置语言的过程
    小程序感悟123
    如何用php实现分页效果
    如何利用h5将视频设置为背景
    关于js中定时器的返回值问题
    canvas二:绘制圆和其他曲线
    canvas一:基本认识
  • 原文地址:https://www.cnblogs.com/xzxl/p/9713327.html
Copyright © 2011-2022 走看看