随笔分类 - PAT (Basic Level) Practice
本人刷PAT乙级的记录
摘要:1015 德才论 (25分) 分四个等级的排序,想简化的朋友可以用结构体数组容器存储啦~ #include<iostream> #include<vector> #include<ctype.h> #include<algorithm> #include<sstream> #include<stri
阅读全文
摘要:1024 科学计数法 (20分) substr():substr(起始位置,往后要几个字符) stoi():string转换为int,参数必须是字符串,字符的话用substr(ch,1)转换为字符串 常用字符串处理函数: 参数是字符即可 isalpha();//是否为字母 isdigit();//是
阅读全文
摘要:1014 福尔摩斯的约会 (20分) 这道题坑多,看清题目要求 第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 D,只能是A~G 第 2 对相同的字符:0 点到 23 点由数字 0 到 9、以及大写字母 A 到 N 表示 后面两字符串第 1 对相同的英文字母 s 出现在第 4 个位置(
阅读全文
摘要:1031 查验身份证 (15分) 把不符合的输出 没有就输出All passed #include<iostream> #include<ctype.h> #include<sstream> #include<string> #include<cstdio> const int maxn=110;
阅读全文
摘要:知道stringstream这个类型就很简单 用于把空格过滤掉 stringstream ss(s);//初始化ss string word; int cnt=0; while(ss >> word){ str[cnt++]=word;//将输入的一行字符串依次存入字符串数组中 } #include
阅读全文
摘要:1002 写出这个数 (20分) [1002 写出这个数 (20分)](https://pintia.cn/problem-sets/994805260223102976/problems/994805324509200384) #include<iostream> #include<string>
阅读全文
摘要:1021 个位数统计 (15分) #include<iostream> #include<string> #include<cstdio> using namespace std; int main(){ string s;cin>>s; int a[1005]={0}; for(int i=0;i
阅读全文
摘要:1006 换个格式输出整数 (15分) #include<iostream> #include<string> #include<cstdio> using namespace std; int main(){ int n;cin>>n; string s=to_string(n); if(s.le
阅读全文
摘要:1037 在霍格沃茨找零钱 (20分) 跟时间小时分钟题的进制转换大体一样,模拟一下 #include<iostream> #include<cstdio> const int Galleon=17*29; const int Sickle=29; using namespace std; int
阅读全文
摘要:1022 D进制的A+B (20分) 这题是十进制转换为d进制的题 从后往前存入的 do{ z[num++]=n%d; n/=d; }while(n!=0); #include<iostream> using namespace std; int main(){ int a,b,d;cin>>a>>
阅读全文
摘要:1027 打印沙漏 (20分) 注意输出的字符是自己输入的,不是固定的'*' 先求出多少层,然后到一定条件反转一下就行了 #include<iostream> using namespace std; int main(){ int n,m; string s; cin>>n>>s; int lev
阅读全文
摘要:1036 跟奥巴马一起编程 (15分) 注意一下空格就行了 #include<iostream> #include<algorithm> using namespace std; int main(){ int n,m;string s; cin>>n>>s; if(n%2){ m=n/2+1; }
阅读全文
摘要:1032 挖掘机技术哪家强 (20分) 从 1 开始连续编号 #include<iostream> #include<algorithm> const int maxn =100005; using namespace std; struct Node{ int id,grade=0; }stu[m
阅读全文
摘要:用容器存数组简单一些,字符串string好些 一个坑点就是没有有效生日,只输出0 #include<iostream> #include<vector> #include<cstdio> #include<algorithm> using namespace std; struct Node{ st
阅读全文
摘要:1004 成绩排名 (20分) 直接sort了,找最大最小值 #include<iostream> #include<algorithm> using namespace std; struct Node{ string name; string id; int grade; }; bool cmp
阅读全文
摘要:1041 考试座位号 (15分) 先附上自己写的辣鸡代码,第一次非常傻,查找输入的id,用了双重for循环 虽然这次数据小体现不出来,但是下次要注意orz #include<iostream> const int maxn = 1005; using namespace std; struct No
阅读全文
摘要:自己写一个划拳的change函数来调用 并且用字符数组来存放输入的字符 最重要的就是一个循环相克 0 1 2 布 石头 剪刀 (k1+1)%3 == k2 为赢 ,反之为输,k1==k2为平 #include<iostream> #include<cstdio> #include<cstring>
阅读全文
摘要:1012 数字分类 (20分) 有个卡点就是A2可能加加减减就为0了,对此进行排查 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main() { int n; cin>>n; int
阅读全文
摘要:1008 数组元素循环右移问题 (20分) 本题有个注意点:当m超过n的值时,循环重复,本身取余 #include<iostream> #include<algorithm> #include<vector> using namespace std; int main(){ int n,m; cin
阅读全文
摘要:1046 划拳 (15分) 简单模拟 #include<iostream> using namespace std; int main(){ int n;cin>>n; int ans1=0,ans2=0; while(n--){ int a1,a2,b1,b2; cin>>a1>>a2>>b1>>
阅读全文