第一范文网 - 专业文章范例文档资料分享平台

C语言基础

来源:用户分享 时间:2025/8/25 20:04:40 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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语言基础 的文档
C语言基础.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c9luq34roz941z4g1ryxy_9.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top