请问这道题目如何实现。

byran1 2008-03-27 01:41:56
提示用户输入一组数字然后从大到小依次输出
菜鸟一个,请高手指点下。。。
...全文
73 12 打赏 收藏 举报
写回复
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mjf_2008 2008-03-27
  • 打赏
  • 举报
回复
感觉都是不错方法,其实说白了都是一个方法
hai040 2008-03-27
  • 打赏
  • 举报
回复
直接用set存然后输出
hanlin1985 2008-03-27
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include "stdlib.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> values;
int value;
cout<<"输入一组数字:"<<endl;
while(cin>>value)
{
values.push_back(value);
}
sort(values.begin(),values.end());
for(vector<int>::reverse_iterator itr=values.rbegin();itr!=values.rend();itr++)
cout<<*itr<<" ";
cout<<endl<<endl;
cin.get();
return 0;
}//ctrl+z表示输入结束
Proteas 2008-03-27
  • 打赏
  • 举报
回复
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
int main(int argc, _TCHAR* argv[])
{
cout<<"输入数字,以a结束输入或者以\"ctrl+Z\":"<<endl;
//////////////////////////////////////////////////////////////////////////
istream_iterator<int> intReader(cin);
istream_iterator<int> intEOF;
ostream_iterator<int> intWriter(cout,">");
vector<int> intVec;
while (intReader != intEOF)
{
intVec.push_back(*intReader);
if (*intReader == 'a')
{
break;
}
++intReader;
}
sort(intVec.begin(),intVec.end());
copy(intVec.rbegin(),intVec.rend(),intWriter);
cout<<endl;
system("pause");
return 0;
}
ttkk_2007 2008-03-27
  • 打赏
  • 举报
回复

int main(void)
{
vector<int> v;
int i;
while(cin>>i)
v.push_back(i);
sort(v.begin(), v.end());
typedef vector<int>::iterator Iter;
Iter iter = v.begin();
for(; iter!= v.end(); ++iter){
cout << *iter << ends;
}
return 0;
}
ryfdizuo 2008-03-27
  • 打赏
  • 举报
回复
ctrl+z表示输入结束;
ryfdizuo 2008-03-27
  • 打赏
  • 举报
回复
#include <list>
#include <iostream>
using namespace std;

bool Com(int i, int j)
{
return i>j;
}
int main()
{
list<int> ListInput;
int i=0, tem;
while(cin>>tem)
ListInput.push_back(tem);

ListInput.sort(Com);
for(list<int>::iterator Iter=ListInput.begin(); Iter!=ListInput.end(); Iter++)
cout<<*Iter<<"\t";
return 0;
}
tsocpp 2008-03-27
  • 打赏
  • 举报
回复
写三个函数
一个负责处理用户输入的一组数字:
还有一个负责对这组数字进行排序;
最后就是将排序外的这组数输出

每个函数的具体实现其实很简单了
学编程就是要自己多动脑,多动手了
不要太依赖别人
zixin_yu 2008-03-27
  • 打赏
  • 举报
回复
1, 提示用户输入数据: printf and scanf
2, 将其保存在数组中
3, 对数组进行冒泡或是选择排序
4, for 循环依次输出: printf
Supper_Jerry 2008-03-27
  • 打赏
  • 举报
回复
使用stl 泛型算法
qmm161 2008-03-27
  • 打赏
  • 举报
回复
输入,排序,输出
clhposs 2008-03-27
  • 打赏
  • 举报
回复
冒泡排序法
相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-03-27 01:41
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下