解题思路:
注意事项:
参考代码:
#include <deque>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <iterator>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <string>
#include <cmath>
#include <string.h>
using namespace std;
int main()
{
deque<int> q;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int num;
cin>>num;
q.push_back(num);
}
int pp,i,j;
for(i=0;i<n-1;i++)
{
int temp=i;
for(j=i+1;j<n;j++)
{
if(q[temp]>q[j])
{
temp=j;
}
}
pp=q[i];
q[i]=q[temp];
q[temp]=pp;
cout<<"swap(a["<<i<<"], a["<<temp<<"]):";
copy(q.begin(),q.end(),ostream_iterator<int>(cout," "));
cout<<endl;
}
cout<<"swap(a["<<n-1<<"], a["<<n-1<<"]):";
copy(q.begin(),q.end(),ostream_iterator<int>(cout," "));
return 0;
}
0.0分
0 人评分
简单的a+b (C语言代码)浏览:719 |
人见人爱A+B (C语言代码)浏览:663 |
Pascal三角 (C语言代码)浏览:1252 |
成绩转换 (C语言代码)浏览:1048 |
【排队买票】 (C语言代码)浏览:944 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:544 |
1025题解浏览:796 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:513 |
C二级辅导-求偶数和 (C语言代码)浏览:707 |
Hello, world! (C语言代码)浏览:916 |