C语言基础

2026/4/29 0:46:14

4 1001 Li 76 1002 Zhang 92 1003 Liu 85 1004 Wang 70

Sample Output

1004 Wang 70 1001 Li 76 1003 Liu 85 1002 Zhang 92

Source

两种方法 1. 冒泡排序版

#include int main(void) { typedefstruct{char a[80];char b[80];int s;}grade; int n; while(scanf(\ { gradestr[n+1],str2; inti,j; for(i=1;i<=n;i++) scanf(\ for(i=1;i

} 2.

for(j=i;j<=n;j++) if(str[i].s>str[j].s){ str2=str[i]; str[i]=str[j]; str[j]=str2; } for(i=1;i<=n;i++) printf(\}

return 0;

Sort函数

#include #include using namespace std; typedefstruct{ char a[20],b[20]; int s; }grade;

boolcmp(grade a,grade b){ returna.s

int main(void) {

int n;

gradestr[25],str2;

while(scanf(\ { inti,j; for(i=1;i<=n;i++) scanf(\ sort(str+1,str+n+1,cmp); for(i=1;i<=n;i++) printf(\ }

return 0; }

4016

Description

一个猴子在一座不超过30级的小山上爬山跳跃,猴子上山一步可跳1级或跳3级,试求上山有多少种不同的爬法

Input

多组测试数据,每组输入1个整数n,表示山的台阶数

Output

对于输入的整数n求出多少种爬法

Sample Input

30

Sample Output

58425

Source

分析:类似与铺瓷砖用f[i]代表到i米高的地方的走法总数,那么考虑到之前的位置只能在i-1和i-3,根据加法原理,f[i]=f[i-1]+f[i-2];初始状态f[1]=1;f[2]=1;f[3]=2; 代码:

#include int main(){ intn,a[31]; a[1]=1;a[2]=1;a[3]=2; for(int i=4;i<=30;i++) a[i]=a[i-1]+a[i-3]; while(~scanf(\ printf(\ } return 0; }

4022

Description

把1到n2的正整数从左上角开始由外层至中心按照顺时针方向螺旋排列

Input

输入整数n (1 <= n <= 10)

Output

按示例输出矩阵

Sample Input

3 4

Sample Output

1 2 3 8 9 4 7 6 5

1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7

Source

如果我不写注释你能看懂吗? 代码:

#include int main(void){ intn,i,j,a[10][10]={0}; while(~scanf(\ int count=1,d=0;//d表示圈数


C语言基础.doc 将本文的Word文档下载到电脑
搜索更多关于: C语言基础 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219