PAT b1001-1005题解
来源:互联网 发布:debian安装软件命令 编辑:程序博客网 时间:2024/05/17 23:54
一、b1001
#include <cstdio>int main(){int n, step;scanf("%d", &n);while(n != 1){if(n % 2 == 0) n /= 2;else n = ( 3 * n + 1) / 2;step++;}printf("%d\n", step);return 0;}
二、b1002
#include <cstdio>#include <cstring>char a[105];char* change(int n){switch(n){case 0: return "ling"; break;case 1: return "yi"; break;case 2: return "er"; break;case 3: return "san"; break;case 4: return "si"; break;case 5: return "wu"; break;case 6: return "liu"; break;case 7: return "qi"; break;case 8: return "ba"; break;case 9: return "jiu"; break;}}int main(){scanf("%s", a);int len, sum = 0;len = strlen(a);for(int i = 0; i < len; i++){sum = sum + a[i] - '0';}int bai = 0, shi = 0, ge = 0;bai = sum / 100;shi = sum / 10 % 10;ge = sum % 10;if(bai != 0){printf("%s ", change(bai));printf("%s ", change(shi));printf("%s", change(ge));}else if(shi != 0){printf("%s ", change(shi));printf("%s", change(ge));}else{printf("%s", change(ge));}return 0;}
三、b1003
#include <cstdio>#include <cstring>int main(){int T;scanf("%d", &T);while(T--){char str[110];scanf("%s", str);int len = strlen(str);int num_p = 0, num_t = 0, other = 0;int loc_p = -1, loc_t = -1;for(int i = 0; i < len; i++){if(str[i] == 'P'){num_p++;loc_p = i;}else if(str[i] == 'T'){num_t++;loc_t = i;}else if(str[i] != 'A') other++;}if((num_p != 1) || (num_t != 1) || (other != 0) || (loc_t - loc_p <= 1)){printf("NO\n");continue;}int x = loc_p, y = loc_t - loc_p - 1, z = len - loc_t - 1;if(z - x * (y - 1) == x){printf("YES\n");}else{printf("NO\n");}}return 0;}
四、b1004
#include <cstdio>struct Student{char name[15];char id[15];int score;} temp, ans_max, ans_min;int main(){int n;scanf("%d", &n); ans_max.score = -1;ans_min.score = 101;for(int i = 0; i < n; i++){scanf("%s%s%d", temp.name, temp.id, &temp.score);if(temp.score > ans_max.score){ans_max = temp;}if(temp.score < ans_min.score){ans_min = temp;}}printf("%s %s\n", ans_max.name, ans_max.id);printf("%s %s", ans_min.name, ans_min.id);return 0;}
五、b1005
#include <cstdio>#include <algorithm>using namespace std;bool cmp(int a, int b){return a > b;}bool hashTable[10000] = {false};int a[110];int main(){int n, m;scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%d", &a[i]);m = a[i];while(m != 1){if(m % 2 == 1){m = (3 * m + 1) / 2;}else {m = m / 2;}hashTable[m] = true;}}int count = 0;for(int i = 0; i < n; i++){if(hashTable[a[i]] == false){count++;}}sort(a, a + n, cmp);for(int i = 0; i < n; i++){if(hashTable[a[i]] == false){printf("%d", a[i]);count--;if(count > 0) printf(" ");}}return 0;}
阅读全文
1 0
- PAT b1001-1005题解
- [PAT] B1001
- PAT B1001
- B1001
- PAT题源分析及思考——B1001
- 算法笔记 PAT B1001 (3n+1猜想)
- PAT 乙级真题题解1001~1005
- PAT B1001 害死人不偿命的(3n+1)猜想 (15) (模拟)
- pat-b1001. 害死人不偿命的(3n+1)猜想 (15)
- PAT B1001. 害死人不偿命的(3n+1)猜想
- 【PAT B1001】害死人不偿命的(3n+1猜想)
- PAT 1001-1010 题解
- PAT 1011-1020 题解
- PAT 1021-1030 题解
- PAT 1031-1040 题解
- PAT 1041-1050 题解
- PAT 1051-1060 题解
- PAT(basic level)题解
- 测试开发行业正在洗牌,新的机会是什么
- 欢迎使用CSDN-markdown编辑器
- 从尾到头打印链表
- 3611: [Heoi2014]大工程
- windows操作系统之间的时间精确同步
- PAT b1001-1005题解
- C++中内存分配方式、空指针及野指针的区别
- 2017.7.7 C组总结
- 通过Lua代码创建一个Cube,并实现控制行走
- 补间动画
- Liferay DXP Soy porlet系列(四)使用Promise对象访问Liferay web service
- android广告自动设置时间跳界面
- 重建二叉树
- eclipse运行慢经常卡死解决方法