#include<stdio.h>                            //选择排序法
int main(){
int n,a[];
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
} for(int i=;i<n-;i++){
int k=i,t;
for(int j=i+;j<n;j++)
if(a[k]<a[j])
k=j;
if(k!=i){
t=a[i];
a[i]=a[k];
a[k]=t;
}
}
for(int i=;i<n-;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-]);
}
return ;
}
#include<stdio.h>                            //冒泡排序法
#include<stdio.h>
int main(){
int n,a[];
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++)
scanf("%d",&a[i]); int t;
for(int i=;i<n;i++){
int flag=;
for(int j=;j<n-i;j++){
if(a[j]<a[j+]){
t=a[j];
a[j]=a[j+];
a[j+]=t;
flag=;
}
if(flag==) break;
}
} for(int i=;i<n-;i++){
printf("%d ",a[i]);
}
printf("%d\n",a[n-]);
} return ;
}

#include<stdio.h>                        //冒泡排序  改进后的

int main(){
int n,a[];
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++)
scanf("%d",&a[i]); int t;
for(int i=;i<n;i++){
for(int j=;j<n-i;j++){
if(a[j]<a[j+]){
t=a[j];
a[j]=a[j+];
a[j+]=t;
}
}
} for(int i=;i<n-;i++){
printf("%d ",a[i]);
}
printf("%d\n",a[n-]);
} return ;
}

Problem J: 零起点学算法89——程序设计竞赛的更多相关文章

  1. Problem J: 零起点学算法105——C语言合法标识符

    #include<stdio.h> #include<ctype.h>//调用isalpha函数 int main() { int n; ]; while(scanf(&quo ...

  2. Problem J: 零起点学算法34——3n+1问题

    #include<stdio.h> int main() { ; int n; scanf("%d",&n); ) { ==) n=n*+; else n/=; ...

  3. Problem H: 零起点学算法28——参加程序设计竞赛

    #include<stdio.h> int main() { int a,b; while(scanf("%d %d",&a,&b)!=EOF) ||b ...

  4. 武汉科技大学ACM:1010: 零起点学算法89——母牛的故事

    Problem Description 有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年的时候,共有多少头母牛? Input 输入数据由多个测 ...

  5. Problem D: 零起点学算法95——弓型矩阵

    #include<stdio.h> #include<string.h> int main() { ][]; while(scanf("%d%d",& ...

  6. Problem D: 零起点学算法94——输出矩阵

    #include<stdio.h> int main() { ][]; while(scanf("%d %d",&n,&m)!=EOF) { ; ;i& ...

  7. Problem C: 零起点学算法93——矩阵转置

    #include<stdio.h> int main() { ][],b[][]; while(scanf("%d%d",&n,&m)!=EOF) { ...

  8. Problem A: 零起点学算法91——找出一个数组中出现次数最多的那个元素

    #include<stdio.h> int main() { ],b[]={}; while(scanf("%d",&n)!=EOF) { ;i<n;i+ ...

  9. Problem H: 零起点学算法87——打印所有低于平均分的分数

    #include<stdio.h> int main(){ ],b[]; while(scanf("%d",&n)!=EOF){ ; ;i<n;i++){ ...

随机推荐

  1. Coursera在线学习---第八节.K-means聚类算法与主成分分析(PCA)

    一.K-means聚类中心初始化问题. 1)随机初始化各个簇类的中心,进行迭代,直到收敛,并计算代价函数J. 如果k=2~10,可以进行上述步骤100次,并分别计算代价函数J,选取J值最小的一种聚类情 ...

  2. linux下实现在程序运行时的函数替换(热补丁)【转】

    转自:http://www.cnblogs.com/leo0000/p/5632642.html 声明:以下的代码成果,是参考了网上的injso技术,在本文的最后会给出地址,同时非常感谢injso技术 ...

  3. 手動設定 電池溫度 mtk platform

    adb root adb shell echo "3 1 27" > ./proc/mtk_battery_cmd/battery_cmd 27 即是所要設定的溫度, 此設定 ...

  4. C#数据没初始化,使用会报错,可以初始化null

    protected void Page_Load(object sender, EventArgs e) { string[] A; if (B== 0) { A = new string[] {1, ...

  5. linux和ubuntu防火墙相关命令

    1.永久有效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2.即刻生效 开启: service iptables start 关闭: se ...

  6. 小白成长记-----python实现注册的小程序

    # 3.写一个注册的程序,输入username,密码,# 密码确认,输入的账号和密码不能为空,两次输入密码必须一致,# 用户名不能重复,错误次数四次 .注册成功提示成功# 把注册账号密码信息的写到文件 ...

  7. Leetcode 之Count and Say(35)

    很有意思的一道题,不好想啊. string getNext(string &s) { ]; ; stringstream ss; ; i < s.size(); i++) { if (s ...

  8. setTimeout(fn,0)

    我们都知道setTimeout是一个延迟执行的函数 console.log(); setTimeout(function(){console.log();},); console.log(); 会得到 ...

  9. [].forEach.call($$("*"),function(a){ a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16) })

    问问你自己,看得懂这行代码吗?要是看不懂就点击进来看看吧,要是看的懂得话,可以绕路 1.call:call(thisObj,arg1,arg2,arg3) [].forEach.call($$(&qu ...

  10. 【转载】Web开发技术发展历史-版本1

    原文在这里. Web开发技术发展历史 Web的诞生 提到Web,不得不提一个词就是“互联网”.Web是World Wide Web的简称,中文译为万维网.“万维网”和我们经常说的“互联网”是两个联系极 ...