题解 | #明明的随机数#

明明的随机数

http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

1.输入
没有输入就结束,用while(cin>>tem)

2.思路
排序,去重
sort升序排序,(升,less;降,greater)
去重,简单比较
最后清空vector

3.代码
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;</algorithm></string></vector></iostream>

int main()
{
vector<int> one_data;
int tem;
int i;
while(cin>>tem)
{
one_data.push_back(tem);
if((one_data.size()-1 == one_data.front())&&one_data.size() != 0)
{
sort(one_data.begin()+1,one_data.end(),less<int>());
int a,b;
for(int j = 1;j<one_data.front();j++)
{
a = one_data[j];
b = one_data[j+1];
if(a!=b)
cout<<a<<endl;
}
cout<<one_data.back()<<endl;
one_data.clear();
}</int></int>

}

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务