关于PAT1004和1005的看法
来源:互联网 发布:宏观经济基础数据库 编辑:程序博客网 时间:2024/06/06 06:52
1004是用max和min存放最大成绩和最小成绩及其相关信息,不难。
1005是要求寻找“覆盖的数”,其关键是在完成判断之后按顺序输出。我认为在开头就排序比较好。
PAT1004代码:
#include<stdio.h>#include<string.h> int main(){ char tempName[15], tempClass[15], maxName[15], maxClass[15], minName[15], minClass[15]; int tempScore, maxScore = 0, minScore = 100, n; scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%s %s %d", tempName, tempClass, &tempScore); if(tempScore > maxScore){ maxScore = tempScore; strcpy(maxName,tempName); strcpy(maxClass,tempClass); } if(tempScore < minScore){ minScore = tempScore; strcpy(minName,tempName); strcpy(minClass,tempClass); } } printf("%s %s\n", maxName, maxClass); printf("%s %s\n", minName, minClass);}
PAT1005代码:
#include<stdio.h>#include<string.h>int main(){ int k; scanf("%d", &k); int a[k]; for(int i = 0; i < k; i++){ scanf("%d", &a[i]); } for(int i = k-1; i > -1; i--){ //冒泡排序 for(int j = k-1; j > -1; j--){ int t; if(a[i] > a[j]){ t = a[i]; a[i] = a[j]; a[j] = t; } } } for(int i = 0; i < k; i++){ int temp, a1; a1 = a[i]; temp = a[i]; while(temp != 1 && temp != 0){ if(a1 % 2 == 0){ temp = a1 / 2; }else{ temp = (3 * a1 + 1) / 2; } for(int j = 0; j < k; j++){ if(a[j] == temp){ a[j] = 0; break; } } a1 = temp; } } int total = 0; int cnt = 1; for(int i = 0; i < k; i++){ if(a[i] != 0){ total++; } } for(int i = k-1; i >= 0; i--){ if(a[i] != 0){ if(cnt != total){ printf("%d ", a[i]); cnt++; }else{ printf("%d", a[i]); } } }}
希望各位大大批评指正!
0 0
- 关于PAT1004和1005的看法
- 关于爱情和婚姻的一点看法
- 关于webcontrol和pagelet的一点看法
- 关于考研的动机和看法
- 关于放大和缩小的看法
- 关于Qrcode和zxing的一些看法
- 关于iTween的一些总结和看法
- 关于JVM的一些看法和笔记
- 关于StringBuffer和StringBuilder的一点看法
- PAT1004福尔摩斯的约会
- PAT1004
- pat1004
- PAT1004
- pat1004
- pat1004
- PAT1004
- pat1004
- PAT1004
- 正则表达式30分钟入门教程
- setsockopt详解
- 属性 iOS笔记
- 数组与指针详解
- 鲁大师检测硬盘提示有问题,如下图,是怎么回事?硬盘坏了吗
- 关于PAT1004和1005的看法
- 认识标签
- XMPP框架 微信项目开发之XMPP框架目录作用详解——以及登录的Demo分析
- Codeforces 547B Mike and Feet
- SSIS初识
- ECMall模板解析语法与机制
- php操作Excel文件,将Excel中数据导入到数据库
- android_01Activity_知识小结
- 相对布局(RelativeLayout)写的QQ登录界面