PAT (Basic Level) Practice (中文
aite_
人间值得
展开
-
1057.数零壹
#include <iostream>using namespace std;int main() { string s; getline(cin, s); int sum = 0; for(int i = 0; i < s.length(); i++) { if(s[i] >= 'A' && s[i] <= 'Z') { su...原创 2018-05-31 13:23:16 · 228 阅读 · 0 评论 -
1047.编程团体赛
#include <iostream>#include <cstdio>using namespace std;int main() { int n; cin >> n; int num[100000] = {0}; int max = 0; int number = 0; for(int i = 0; i < n; i++) { ...原创 2018-05-23 13:21:17 · 172 阅读 · 0 评论 -
1046.划拳
要注意喊得相等的情况。#include <iostream>using namespace std;int main() { int n; cin >> n; int a[101][101]; for(int i = 0; i < n; i++) { for(int j = 0; j < 4; j++) { cin >>...原创 2018-05-23 13:10:58 · 190 阅读 · 0 评论 -
1045.快速排序
如果按照题目正常写的话就只有第一个点能通过,结果超时,后来观察到可以和排好序的数组比较,数字相等的时候才能算,但是也有一半的点是不能通过的,后来,想到了如果有两个相同的数字,那么在排序的过程中,两个数字就是挨着的,那么就没办法与未排序的数组一一对应了,这样就判断一下,需要判断的数字是否比之前的最大值大。做完以上这些步骤,我觉得应该可以通过了,但是还是有一个点过不去,试了很久,就是要在结尾加换行,不...原创 2018-05-23 12:56:49 · 222 阅读 · 0 评论 -
1051.复数乘法
#include <bits/stdc++.h>using namespace std;int main(){ double r1, p1, r2, p2; cin >> r1 >> p1 >> r2 >> p2; double a = r1 * r2 * cos(p1) * cos(p2) - r1 * r2 * si...原创 2018-05-26 15:54:08 · 391 阅读 · 0 评论 -
1044.火星数字
#include<iostream>#include<string>#include<sstream>using namespace std;int toInt(string str) { int n; stringstream s; s << str; s >> n; return n;...原创 2018-05-21 14:45:12 · 277 阅读 · 0 评论 -
1043.输出PATest
用了一个不动脑的方法#include <bits/stdc++.h>#include <string.h>using namespace std;int main(){ char s[10001]; gets(s); int length = strlen(s); char s1[10001]; int k = 0; int a[6] = {0};...原创 2018-05-21 12:38:05 · 359 阅读 · 0 评论 -
1042.字符统计
在提交时有一个点没有过去,后来读题发现自己忽略了细节“如果有并列,则输出按字母序最小的那个字母。”,所以在循环里加一次判断并列的条件。#include <iostream>using namespace std;int main() { string s; getline(cin, s); int a[100001] = {0}; int max = 0; char b...原创 2018-05-21 12:34:15 · 460 阅读 · 0 评论 -
1031. 查验身份证
题目在这里将权重,对应值和校验码都放到数组中,将不符合要求的字符串存到vector中,如果都符合要求,直接输出“All passed”.#include <iostream>#include <vector>using namespace std;int main(){ int q[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7,...原创 2018-05-07 14:20:49 · 257 阅读 · 0 评论 -
1032. 挖掘机技术哪家强
题目在这里将最大值的位置记录下来,用数组下标当作班级编号。#include <iostream>using namespace std;int main(){ int n; cin >> n; int a[100001] = {0}; int max = 0; for(int i = 0; i < n; i++) { int num, grad...原创 2018-05-05 15:45:03 · 87 阅读 · 0 评论 -
1040.有几个PAT
有两个要注意的点,一开始没有注意到要取1000000007的余,后来在结果处改正,可是还是有两个点过不去,应该是int的取值范围存不下的原因,所以改成了在计算过程中取余即可。#include <iostream>using namespace std; int main() { string str; cin >> str; int numT = 0; int...原创 2018-05-18 13:05:21 · 219 阅读 · 0 评论 -
1039.到底买不买
#include <iostream>using namespace std;int main() { string s1, s2; cin >> s1 >> s2; int count = 0; int flag = 0; for(int i = 0; i < s2.length(); i++) { for(int j = 0; j ...原创 2018-05-18 12:44:03 · 183 阅读 · 0 评论 -
1038.统计同成绩学生
#include <iostream>using namespace std;int main() { int n; cin >> n; int a[100001] = {0}; for(int i = 0; i < n; i++) { int num; cin >> num; a[num]++; } int m; cin ...原创 2018-05-18 12:35:03 · 228 阅读 · 0 评论 -
1037.在霍格沃茨找零钱
#include <iostream>#include <bits/stdc++.h>using namespace std;int main() { int a1, a2, a3; int b1, b2, b3; scanf("%d.%d.%d", &a1, &a2, &a3); scanf("%d.%d.%d", &b1,...原创 2018-05-18 12:31:24 · 102 阅读 · 0 评论 -
1048.数字加密
要考虑两个字符串不相等的情况。#include <iostream>#include <vector>#include <bits/stdc++.h>using namespace std;int main() { string s, s1; cin >> s >> s1; int ka = 1; int a[10001...原创 2018-05-23 13:51:49 · 184 阅读 · 0 评论 -
1049.数列的片段和
用了一个投机取巧的方法,数了每个数的个数,找规律再相加。#include <iostream>#include <cstdio>using namespace std;int main() { int n; cin >> n; double sum = 0.0; for(int i = 0; i < n; i++) { double a...原创 2018-05-23 14:00:09 · 143 阅读 · 0 评论 -
1056.组合数的和
每个数在个位和十位分别会计算几次,然后计算他们的总和。#include <iostream>using namespace std;int main() { int n; cin >> n; int sum = 0; int a[10001]; for(int i = 0; i < n; i++) { cin >> a[i]; } ...原创 2018-05-31 12:41:06 · 174 阅读 · 0 评论 -
1055.集体照
画图更清晰#include <iostream>#include <bits/stdc++.h>using namespace std;struct student { string s; int h;};bool cmp(struct student &a, struct student &b) { if(a.h == b.h) { ...原创 2018-05-31 12:34:20 · 297 阅读 · 0 评论 -
1024.科学计数法
空了很久这个题,之前觉得很难,后来想了一下,捋清思路之后准备做一下,用了不是很简单的方法,但是容易懂。直接计算小数点左右的位数,直接输出字符串从“.”到“E”之间的字符。#include <iostream>using namespace std;int main() { string s; cin >> s; int e; for(int i = 0; i ...原创 2018-06-06 13:13:07 · 337 阅读 · 0 评论 -
1061.判断题
#include <iostream>using namespace std;int main() { int n, m; cin >> n >> m; int t[1001]; int d[1001]; for(int i = 0; i < m; i++) { cin >> t[i]; } for(int i = 0;...原创 2018-06-06 12:32:44 · 340 阅读 · 0 评论 -
1054.求平均值
#include <bits/stdc++.h>#include <stdlib.h>using namespace std;bool check(string s){ bool flag = true; int countp = 0; int countn = 0; for (int i = 0; i < s.length(); i ++) { ...原创 2018-05-29 20:51:18 · 254 阅读 · 0 评论 -
1064.朋友数
#include <bits/stdc++.h>using namespace std;int main(){ int n; cin >> n; int k = 0; int a[10001]; bool flag; for(int i = 0; i < n; i++) { flag = true; int number; cin >...原创 2018-06-12 16:33:25 · 203 阅读 · 0 评论 -
1063.计算谱半径
#include <cmath>#include <iostream>using namespace std;int main() { int n; cin >> n; double sum, max = 0.00; for(int i = 0; i < n; i++) { int numbers, numberx; cin >...原创 2018-06-12 16:24:39 · 220 阅读 · 0 评论 -
1060.爱丁顿数
数组从大到小排列,最大的一定有一个它本身,按照顺序,直到数字不大于天数截止增加。#include <bits/stdc++.h>using namespace std;bool cmp(int a, int b) { return a > b;}int main() { int n; cin >> n; int a[100001]; for(in...原创 2018-06-05 14:52:17 · 285 阅读 · 0 评论 -
1059.C语言竞赛
注意输出时是四位整数#include <iostream>#include <bits/stdc++.h>using namespace std;bool judge(int number) { int m = sqrt(number); if(number <= 1) { return false; } else { for(int i = 2...原创 2018-06-05 14:44:20 · 336 阅读 · 0 评论 -
1053.住房空置率
#include <iostream>#include <cstdio>using namespace std;int main() { int n, D; double e; cin >> n >> e >> D; int may = 0, must = 0; for(int i = 0; i < n; i++)...原创 2018-05-29 12:52:19 · 290 阅读 · 0 评论 -
1052.卖个萌
要注意输出“Are you kidding me? @\/@”时,在双引号中表示‘\’要用双斜杠表示,否则会出错。#include <iostream>#include <vector>using namespace std;vector<string> extract(string s) { vector<string> v; stri...原创 2018-05-29 12:35:57 · 527 阅读 · 0 评论 -
1058.选择题
这题写的很困难#include <bits/stdc++.h>using namespace std;struct node{ int f, z; char ans[10];};int main(){ int n, m, temp; char c; cin >> n >> m; int score[1001] = {0}; int...原创 2018-06-04 15:34:13 · 382 阅读 · 0 评论 -
1050.螺旋矩阵(24)
最后一个测试点超时#include <iostream>#include <bits/stdc++.h>using namespace std;bool cmp(int a, int b) { return a > b;}int main() { int N; cin >> N; int a[10001]; int b[101][1...原创 2018-05-23 16:01:16 · 246 阅读 · 0 评论 -
1036.跟奥巴马一起编程
#include <iostream>using namespace std;int main() { int n; char a; cin >> n >> a; int m = n / 2; if(n % 2 != 0) { m++; } for(int i = 0; i < m; i++) { if(i == 0 || i ...原创 2018-05-18 12:23:58 · 274 阅读 · 0 评论 -
1030. 完美数列
题目在这里p的值要用long long型的,否则结果会溢出。#include <iostream>#include <bits/stdc++.h>using namespace std;int main(){ long long n, p; cin >> n >> p; int a[100001]; for(int i = 0; i...原创 2018-05-03 17:27:07 · 93 阅读 · 0 评论 -
1026. 程序运行时间
点击打开链接#include <iostream>using namespace std;int main(){ int c1, c2; cin >> c1 >> c2; int m = (c2 - c1) / 100; if(m % 100 >= 50) { m++; } int hour = m / 3600; int min...原创 2018-04-21 17:31:17 · 99 阅读 · 0 评论 -
1011. A+B和C
点击打开链接需要注意的是整数的范围,超过了int的范围值,选用long。#include <iostream>using namespace std;int main(){ int n; cin >> n; for(int i = 0; i < n; i++) { long a, b, c; cin >> a >> b &...原创 2018-04-12 14:56:07 · 65 阅读 · 0 评论 -
1010. 一元多项式求导
点击打开链接题目没具体说输入如何结束,就以回车键作为判断,边判断便输出。题目是指数求导,求导后的系数就是原系数和原指数相乘,求导后的指数是原指数减一。#include <bits/stdc++.h>#include <iostream>using namespace std;int main(){ int co, ex; bool flag = true; ...原创 2018-04-12 14:45:52 · 87 阅读 · 0 评论 -
1018. 锤子剪刀布
点击打开链接暴力做法。#include <iostream>#include <bits/stdc++.h>#include <math.h>using namespace std;bool cmp(int a, int b) { return a > b;}int max(int a[], int n) { int b[n]; fo...原创 2018-04-17 22:31:03 · 93 阅读 · 0 评论 -
1017. A除以B
点击打开链接将字符串按位存到整型数组中,按照正常的除法算法,从最高位开始除以被除数,再向后依次相加每一位。注意: 1.要考虑到字符串长度为1的特殊情况,这样只需要输出“0 b”。 2.要考虑得到的除数第一位是0的情况#include <iostream>using namespace std;int main(){ string a; int b...原创 2018-04-17 22:29:56 · 116 阅读 · 0 评论 -
1016. 部分A+B
点击打开链接把输入的数字中按位做除法,当到数字相等的时候就把之前的sum乘以10再累加该数字。得到的两个数的结果相加即可。#include <iostream>using namespace std;int main(){ int a, da, b, db; cin >> a >> da >> b >> db; int co...原创 2018-04-17 22:25:51 · 111 阅读 · 0 评论 -
1009. 说反话
点击打开链接从前向后遍历整个句子,我最开始想要设定一个key关键值,用来记录整个单词的头位置,这样找到空格之后就会知道单词的位置区间,但是到了后面的时候想到设定一个字符串,直接把不是空格的每个字符都加上,遇到空格再把st字符串放到容器vector里面,再重新设置st的值。#include <iostream>#include <vector>using namespac...原创 2018-04-11 13:41:29 · 86 阅读 · 0 评论 -
1008. 数组元素循环右移问题
点击打开链接在判断向后移的过程中要注意,在i加上m后有大于n的可能,也就是需要向前移动的数组,这就需要进行取余操作。#include <iostream>using namespace std;int main(){ int n, m; cin >> n >> m; int a[1001]; for(int i = 0; i < n; ...原创 2018-04-11 13:34:38 · 76 阅读 · 0 评论 -
1007. 素数对猜想
点击打开链接先进行素数判断,单独写出一个函数,因为考虑到下面要进行0 和 2 的比较,所以把小于0的判断和1放在了一起。在主函数中进行计数判断时用 i 和 i - 2判断就不会出现越界情况。#include <iostream>#include <bits/stdc++.h>using namespace std;bool judge(int num) { int...原创 2018-04-11 13:31:26 · 79 阅读 · 0 评论