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

      

  • 相关阅读:
    C语言I博客作业04
    C语言I博客作业03
    C语言1博客作业02
    作业1
    C语言||作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    笔记本
  • 原文地址:https://www.cnblogs.com/xzxl/p/9713327.html
Copyright © 2011-2022 走看看