我是靠谱客的博主 清脆季节,这篇文章主要介绍找出输入数字中只出现了一次的那个数并输出——小米OJ试题,现在分享给大家,希望可以做个参考。

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int i = 0;
		int a = 0;
		vector<int>vec_int;
		while (cin >> a)
		{
			if (i<20 && a<256)
			{
				vec_int.push_back(a);
				i++;
			}
			else
			{
				break;
			}
		}
    //使用排序算法
	sort(vec_int.begin(), vec_int.end());
	for (int i = 0; i<vec_int.size(); i++)
	{
		if (i == 0 && vec_int[i] != vec_int[i+1])
		{
			cout << vec_int[i] << endl;
		}
		else if (i == (vec_int.size() - 1) && vec_int[i] != vec_int[i - 1])
		{
			cout << vec_int[i] << endl;
		}
		else if (vec_int[i] != vec_int[i - 1] && vec_int[i] != vec_int[i + 1])
		{
			cout << vec_int[i] << endl;
		}
	}
}

 

最后

以上就是清脆季节最近收集整理的关于找出输入数字中只出现了一次的那个数并输出——小米OJ试题的全部内容,更多相关找出输入数字中只出现了一次内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部