zoukankan      html  css  js  c++  java
  • 统计工龄

    • 题目描述

    • 题目思路:

    思路比较简单,排序然后输出即可。

    • C++实现
    #include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
    	int N;
    	int i,j;
    	int k;
    	int temp;
    	int count = 0;
    	vector<int> workingyears;
    	cin >> N;
    	for (i = 0;i < N;i++)
    	{
    		cin >> k;
    		workingyears.push_back(k);
    	}
    	sort(workingyears.begin(),workingyears.end());
    
    	for (i = 0;i < N;)
    	{
    		temp = workingyears.at(i);
    		for (j = 0;j < N;j++)
    		{
    			if (temp == workingyears.at(j))
    			{
    				count++;
    			}
    		}
    		cout << workingyears.at(i) << ":" << count << endl;
    		i = i + count;
    		count = 0;
    	}
    	// system("pause");
    	return 0;
    }
    
    • 后记:
      这道题用C++来实现是因为这道题目比较简单,思路一眼就能看出来,我不想再写一遍排序算法, 因此直接调用了STL中的sort()函数。
  • 相关阅读:
    JS中的constructor与prototype
    HTTP状态码
    CSS HACK 及常见问题
    js常见怪异
    js深拷贝和浅拷贝
    浏览器渲染
    google全球地址大全
    从function前面的!想到的
    2048
    js判定IE
  • 原文地址:https://www.cnblogs.com/Manual-Linux/p/11445464.html
Copyright © 2011-2022 走看看