728x90
#include <iostream>
#include <vector>
#include <algorithm> //올림차순쓸때
#include <functional> //내림차순쓸때
#include <stdlib.h> //난수값쓸때
#include <time.h> //난수값쓸때
#include <string>
using std::sort;
int main()
{
int num = 0;
srand((unsigned)time(NULL));
std::vector< int > v;
std::cout<<"생성할 랜덤 백터 값의 갯수 : ";
std::cin>>num;
for(int i = 0; i<num; i++) {
v.push_back((rand()%(1000 - 1)));
}
std::cout<<std::endl;
std::cout<<"오름차순 정렬 전 랜덤 백터 값"<<std::endl;
for(std::vector<int>::iterator iter = v.begin(); iter !=v.end(); iter++) {
std::cout<<*iter<<" ";
}
std::cout<<std::endl;
sort(v.begin(),v.end());
std::cout<<"오름차순 정렬 후 랜덤 백터 값"<<std::endl;
for(std::vector<int>::iterator iter = v.begin(); iter != v.end(); iter++) {
std::cout<<*iter<<" ";
}
std::cout<<std::endl;
sort(v.begin(),v.end(), std::greater<int>());
std::cout<<"내림차순 정렬 후 랜덤 백터 값"<<std::endl;
for(std::vector<int>::iterator iter = v.begin(); iter != v.end(); iter++) {
std::cout<<*iter<<" ";
}
std::cout<<std::endl<<std::endl;
return 0;
} /*실행 값 결과*/
728x90
'프로그래밍-1 > C++' 카테고리의 다른 글
| (Accelerated C++) 학생 성적 계산하기 (0) | 2013.08.18 |
|---|