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;
    }
    

      

  • 相关阅读:
    Qt学习之路,part1
    1.获取状态栏的高度
    如何在Android Studio中上传代码到Gitee上
    关于类图
    外观模式
    关于类的实例
    SharedPreference中关于editor.apply()和editor.commit()
    活动的4种启动模式
    unittest中case批量管理
    unittest使用
  • 原文地址:https://www.cnblogs.com/xzxl/p/9713327.html
Copyright © 2011-2022 走看看