PTA刷题
MokylinJay
Hello World!
展开
-
1002 写出这个数
题目链接注:这道题之前的做法是从前向后拆解sum的值,结果发现测试点1不通过。经过一番思考,原来是当我们从前往后拆解数时,会出现0在首位的情况。例如:101,对10整除后我们会得到01,但是机器只会记录下1,因为我们是以整数保存的,故从前往后分解会出错。下面的解法是将结果从后往前进行拆解,即对10取余。#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h&g原创 2020-11-15 17:14:42 · 123 阅读 · 0 评论 -
1046 划拳 (水题)
题目链接#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>#include <queue>using namespace std;int main(){ // 变量分别为甲喊 乙喊 甲划 乙划 记录数 int a, b, a1, b1, n; int cnt1 =原创 2020-10-30 21:36:51 · 93 阅读 · 0 评论 -
1023 组个最小数(简单贪心)
题目链接#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>#include <queue>using namespace std;int main(){ int a[10] = {0}; for (int i = 0; i < 10; i++) {原创 2020-10-27 21:42:17 · 62 阅读 · 0 评论 -
1020 月饼(简单贪心)
题目链接#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>#include <queue>using namespace std;struct mooncake // 定义mooncake结构体,方便排序{ double store; double totalPri原创 2020-10-27 21:30:01 · 116 阅读 · 0 评论 -
1026 程序运行时间(四舍五入,round函数)
题目链接#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;const double CLK_TCK = 100.0; // 定义CLK_TCK常量int main()原创 2020-10-26 17:26:10 · 225 阅读 · 0 评论 -
1016 部分A+B(pow函数精度问题)
题目链接注意:这种做法要注意pow函数的精度问题,即设置底数为double类型可避免WA#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;int main(){原创 2020-10-26 16:55:42 · 118 阅读 · 0 评论 -
1025 PAT Ranking(结构体排序)
题目链接思路:1. 分考场读入考生数据2. 对每个考场的考生进行排序,并对local_rank进行赋值3. 对全部考生进行排序,以变量r记录考生名次#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>#include <algorithm>using namespace std;struct Student{ char原创 2020-10-25 17:28:39 · 75 阅读 · 0 评论 -
1009 说反话 (20分)
题目链接注意:PTA不支持gets(),所以我选择用cin.get()函数接收一行字符串#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>using namespace std;int main(){ char str[85], ans[85][85]; cin.get(str, 90); int len = strlen原创 2020-10-24 09:50:52 · 66 阅读 · 0 评论 -
1022 D进制的A+B(十进制转其他进制)
题目链接#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ int a, b, d; scanf("%d%d%d", &a, &b, &d); int n = a + b; int ans[40], t = 0; if (n == 0) // 特判 {原创 2020-10-24 08:44:31 · 52 阅读 · 0 评论