HDU 2016 (水)
2024-10-09 00:13:35
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2016
题目大意:给你 n 个数,把最小的数和第一个数字互换,然后输出
解题思路:
很水,开数组,遍历并记录 min ,最后 swap 输出
代码:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
using namespace std;
int num;
int s[];
int main()
{
int n;
int x;
int p;
int min = ;
while(cin >> n && n)
{
// 没必要. memset(s, 0, sizeof(int));
min = ;
for(int i = ; i < n; i ++)
{
cin >> s[i];
if(s[i] < min)
{
min = s[i];
p = i;
}
}
swap(s[], s[p]);
for(int i = ; i < n; i ++)
{
if(i != n - )
cout << s[i] << " " ;
else
cout << s[i] ;
}
//if(n != 0)
cout << endl;
}
}
最新文章
- Android中Fragment和ViewPager那点事儿(仿微信APP)
- HTML转义字符集合
- 在Linux下部署activemq
- HDU-4635 Strongly connected 强连通,缩点
- Linux下套接字具体解释(三)----几种套接字I/O模型
- ZOJ3827 ACM-ICPC 2014 亚洲区域赛的比赛现场牡丹江I称号 Information Entropy 水的问题
- PHP时间戳与时间相互转换(精确到毫秒)
- cron expr
- day4作业小代码练习
- Spring MVC处理(下周完善)
- FreeNas搭建踩坑指南(二)
- Excel表格中依据某一列的值,将这列中一样的数据放在一个文件中。
- vue打包上传oss
- 关闭2010中 word每次都提示:所做更改会影响共用模板 Normal.dotm
- L267 How to save money
- mysql学习笔记(三)
- iOS 设置textfield的最大文本长度
- expect中使用exec执行shell命令
- SpringBoot 之HelloController
- Python自动化之高级语法单例模式
热门文章
- 1. git 本地给远程仓库创建分支 三步法
- SpringCloud(五)学习笔记之Hystrix
- 在Eclipse上实现简单的JDBC增删查改操作
- nginx 配置大吞吐量
- Synchronous and Asynchronous I/O [Windows]
- JAVA企业级应用TOMCAT实战(三)
- Java ASM3学习(3)
- RANet : 分辨率自适应网络,效果和性能的best trade-off | CVPR 2020
- 怎么查看当前的git分支是基于哪个分支创建的?
- c/c++获取文件夹下所有文件名