自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(49)
  • 收藏
  • 关注

原创 PAT笔记 1093 字符串A+B (20分)

题目 思路 用map记录每个字符是否重复出现,初始设置所有字符没有出现,分别遍历a b字符串,每输出一个字符就把该字符标记为输出过,后续遇到标记为输出过的,就不输出了 代码 #include <stdio.h> #include <iostream> #include <string> #include <map> using namespace std; int main(){ string str1,str2; getl..

2020-07-18 22:37:55 118

原创 PAT笔记:1024 科学计数法 (20分)

题目 代码 #include <stdio.h> #include <cstring> #include <iostream> using namespace std; int main(){ char str[10010]; cin.getline(str,10010); int len=strlen(str); if(str[0]=='-'){ //负数 printf("-"); } int ..

2020-07-12 21:58:21 176

原创 PAT笔记:1023 组个最小数 (20分)

题目 代码 #include <iostream> using namespace std; int main(){ int nums[10]={0},t; for(int i=0;i<10;i++){ //记录每个数字的个数 cin>>t; nums[i]=t; } //输出第一位:不为0的最小数 for(int i=1;i<10;i++){ if(nums[i]!=0)..

2020-07-12 21:49:12 114 1

原创 PAT笔记:1022 D进制的A+B (20分)

题目 思路 重点是进行10进制向任意进制的转换。在这里,我使用vector存储待转换数每次除以d的余数,最后逆序输出 代码 #include <iostream> #include <vector> using namespace std; int main(){ int a,b,d; cin>>a>>b>>d; int sum=a+b; //10进制转d进制 vector<int..

2020-07-12 21:41:27 99

原创 PAT笔记:1016 部分A+B (15分)

题目 思路 A B 定义为字符串,DA DB定义为字符,用于比较字符串中有几个字符等于对应字符 将DA DB转换为数字备用,后续用来计算两个和 每遇到相同字符,就将对应的数字加到对应和上,最后输出两个和之和 代码 #include <iostream> using namespace std; int main(){ string a,b; char da,db; cin>>a>>da>>b>>db; .

2020-07-12 01:26:19 98

原创 PAT笔记:1015 德才论 (25分)

题目 思路 把各类考生存入各个数组,排序即可 代码 #include <iostream> #include <algorithm> #include <vector> using namespace std; struct student{ int id,de,cai,sum; }temp; bool cmp(student a,student b){ if(a.sum!=b.sum) return a.sum>b.sum;..

2020-07-12 01:17:20 79

原创 PAT笔记:1014 福尔摩斯的约会 (20分)

题目 代码 #include <iostream> #include <cstring> using namespace std; int main(){ char s1[70],s2[70],s3[70],s4[70]; cin.getline(s1,70); cin.getline(s2,70); cin.getline(s3,70); cin.getline(s4,70); //星期:第 1 对相同的大写英文字母(大小..

2020-07-11 21:33:18 82

原创 PAT笔记:1013 数素数 (20分)

题目 代码 #include <stdio.h> #include <vector> using namespace std; bool is_prime(int n){ //true 是素数 for(int i=2;i*i<=n;i++){ if(n%i==0){ return false; } } return true; } int main(){ int m,n,cnt..

2020-07-11 21:04:23 100

原创 PAT笔记:1012 数字分类 (20分)

题目 思路 按题目要求对不同的数字分别处理即可,各类数字处理结果存放在不同变量中,按需输出 代码 #include <stdio.h> int main(){ int n,a[5]={0},t; scanf("%d",&n); int flag=1,cnt=0,should[5]={0}; for(int i=0;i<n;i++){ //存储所有数字被5除后的结果 scanf("%d",&t); ..

2020-07-11 00:20:49 87

原创 PAT笔记:1011 A+B 和 C (15分)

题目 思路 注意数据范围,用长整型存储 代码 #include <iostream> using namespace std; typedef long long LL; int main(){ LL a,b,c; int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a>>b>>c; if((a+b)>c){ ..

2020-07-11 00:04:42 81

原创 PAT笔记:1010 一元多项式求导 (25分)

题目 代码#include <stdio.h> #include <iostream> using namespace std; int main(){ int t1,t2,flag=0; //flag 为1表示输出一个空格 while(cin>>t1>>t2){ //边输入边求导,输出 if(t2!=0){ if(flag==1) cout<<" "; cout.

2020-07-10 23:59:42 99

原创 PAT笔记:1009 说反话 (20分)

题目 思路 读入字符串,按空格分割字符串,将各个单词存入二维字符串数组中,最后倒序输出该二维数组 注意分割时,每个单词结尾加上'\0' 代码 #include <stdio.h> #include <iostream> using namespace std; int main(){ string s; getline(cin,s); char temp[100][100]; int r=0,c=0; for(int i=0..

2020-07-10 23:44:25 75

原创 PAT笔记:1008 数组元素循环右移问题 (20分)

题目 代码 #include <stdio.h> #include <algorithm> using namespace std; int main(){ int n,m; scanf("%d%d",&n,&m); m%=n; int a[n]; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } reverse(a,a+n); //反..

2020-07-10 23:35:56 67

原创 PAT笔记:1007 素数对猜想 (20分)

题目 思路 先定义判断一个数是否素数的函数is_prime,根据题意,在3~n的范围内,判断“相差为2的两个数是否都是素数”,符合条件则计数器加1 代码 #include <stdio.h> //判断某个数是不是素数 bool is_prime(int n){ if(n<=1) return false; for(int i=2;i*i<=n;i++){ if(n%i==0){ return false; ..

2020-07-10 23:27:31 99

原创 PAT笔记:1006 换个格式输出整数 (15分)

题目 思路 百十个位分别设置循环,按每一位的数值处理输出内容 代码 #include <stdio.h> int main(){ int n; scanf("%d",&n); int b=n/100,s=n%100/10,g=n%10;//三位 //百位 for(int i=0;i<b;i++){ printf("B"); } //十位 for(int i=0;i<s;i++)..

2020-07-10 23:04:25 77

原创 PAT笔记:1005 继续(3n+1)猜想 (25分)

题目 思路 用一个哈希表记录数字是否应该被输出 输入的同时记录按规则生成的数字,将该数字记为不应输出 输入的数字存到数组中 记录应被输出的数据的个数,便于调整输出格式 将输入的数据从大到小排序,用于最后输出 输出数组中标记为“可输出”的值 代码 #include <stdio.h> #include <algorithm> using namespace std; bool cmp(int a,int b){ return a>b; } in..

2020-07-10 21:56:29 91

原创 PAT笔记:1004 成绩排名 (20分)

题目 思路 定义结构体存放每条记录,边读入边比较,不断更新分数最高、最低者的学号、姓名 代码: #include <stdio.h> #include <iostream> using namespace std; struct student{ char name[15]; char id[15]; int score; }temp,Max,Min; int main(){ int n; cin>>n; ..

2020-07-10 21:39:14 100

原创 PAT笔记:1003 我要通过! (20分)

题目 思路 对读入的每个字符串分别处理,记录其中p、t、其他字符的个数,以及p、t的位置,比较左侧a的个数 * 中间a的个数是否等于右侧a的个数 代码 #include <iostream> #include <string> using namespace std; int main(){ int n; cin>>n; string s; for(int i=0;i<n;i++){ cin&gt..

2020-07-09 00:59:20 96

原创 PAT笔记:1002 写出这个数 (20分)

题目 思路 按字符串读取数字,计算各位之和,按和的每一位数字输入对应的数字拼音 代码 #include <stdio.h> #include <string> #include <iostream> using namespace std; int main(){ string s; cin>>s; int sum=0; char a[11][5]={"ling","yi","er","san","si","..

2020-07-09 00:42:01 127

原创 PAT笔记 1076 Wifi密码 (15分)

题目 思路 对于每行输入分别判定和输出,获取每个选项的第三个字符,如果为T,根据第一个字符的选项输出数字 #include <stdio.h> int main(){ int n; scanf("%d",&n); char str[5]; for(int i=0;i<n;i++){ for(int j=1;j<=4;j++){ //输出:每一题的正确选项对应的数字 if(j!=1) sca.

2020-06-08 23:24:50 119

原创 PAT笔记 1066 图像过滤 (15分)

题目 思路 边输入边替换,用二维数组存储和输出 #include <stdio.h> int main(){ int row,col,l,r,ch,t; scanf("%d %d %d %d %d",&row,&col,&l,&r,&ch); int a[row][col]; for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ .

2020-06-08 23:10:13 86

原创 PAT笔记 1063 计算谱半径 (20分)

题目 思路 数学题,引入cmath计算即可 #include <stdio.h> #include <cmath> #include <algorithm> using namespace std; int main(){ int n,t1,t2; scanf("%d",&n); double a[n]; for(int i=0;i<n;i++){ scanf("%d %d",&t1,&a.

2020-06-08 22:25:05 90

原创 PAT笔记 1091 N-自守数 (15分)

题目 思路 依次处理输入的每一个数,记录数字位数n,最后把该数字和的平方从1开始相乘,比较所得结果的最后n位是否等于原数字 #include <stdio.h> #include <cmath> using namespace std; int main(){ int n,t; scanf("%d",&n); for(int i=0;i<n;i++){ int ans=0,cnt=0,num,temp,mod=..

2020-06-07 18:00:22 98

原创 PAT笔记 1069 微博转发抽奖 (20分)

题目 - 思路 - 用map标记某个人是否被抽过奖,按条件判断是否符合抽奖条件即可 - 边判断边记录中奖人数,如果中奖人数为0输出 Keep going... ```cpp #include int main(){ string rec; int m,n,s; scanf("%d %d %d",&m,&n,&s); map<string,int> M; //记录是否已经抽过奖 int cnt=0; //记录中奖人数 for(int i=1;i<=m;i+.

2020-06-06 23:35:45 120

原创 PAT笔记 1059 C语言竞赛 (20分)

题目 思路 分别用三个数组记录id的排名、是否存在、是否被查询过,后续根据条件进行判断、输出即可 #include <stdio.h> #include <cmath> using namespace std; bool isPrime(int n){ bool flag=true; //表示是素数 if(n<=1){ flag=false; }else{ int sqr=sqrt(n*1.0); ..

2020-06-06 16:21:56 104

原创 PAT笔记 1071 小赌怡情 (15分)

题目 思路 先判断筹码总数是否为0,再判断下注筹码够不够,后面根据条件判断就可以了 #include <stdio.h> int main(){ int tot,n; scanf("%d %d",&tot,&n); int n1,n2,t,j; //前后两个数字 下注筹码数 0/1 for(int i=0;i<n;i++){ scanf("%d %d %d %d",&n1,&j,&t,&.

2020-06-06 15:56:34 80

原创 PAT笔记 1072 开学寄语 (20分)

题目 思路 输入违禁物品时用一个数组记录,下标为物品编号,值为1表示禁止携带,后面输入学生名单时对比就可以了 容易出错的地方:输出格式 #include <stdio.h> #include <cstring> using namespace std; int main(){ int n,k; scanf("%d %d",&n,&k); int t,ban[10000]; memset(ban,0,sizeof(ban)).

2020-06-05 21:51:31 71

原创 PAT笔记 1053 住房空置率 (20分)

题目 思路 按题意对出入的数据进行判断,符合条件增加对应的计数就可以了 这里注意百分号%的输出 #include <stdio.h> #include <iostream> using namespace std; int main(){ int n,d; double e; scanf("%d %lf %d",&n,&e,&d); int cnt1=0,cnt2=0; //可能空置 空置 for(int .

2020-06-05 21:02:24 85

原创 PAT笔记 1057 数零壹 (20分)

题目 思路 输入时将大写转换为小写,对小写字符进行转换 计算累加的和,然后分析和转换为2进制的结果 重点:获取每一个小写字母对应的数字 #include <stdio.h> #include <cstring> #include <iostream> using namespace std; int main(){ char str[100005]; cin.getline(str, 100005); int len=strlen(s.

2020-06-05 20:43:44 155

原创 PAT笔记 1062 最简分数 (20分)

题目 (有一个测试点运行超时了) #include <stdio.h> #include <iostream> using namespace std; struct number{ int up,down; }l,r; //找最大公约数 int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int main(){ int t1Up,t1Down,t2Up,t2Down,k; scanf("%d.

2020-06-05 10:25:50 102

原创 PAT笔记 1061 判断题 (15分)

题目 思路 用两个数组分别存储每道题的分值、正确答案,最后边输入边比较答案是否正确,计算总分输出~ #include <stdio.h> #include <vector> using namespace std; int main(){ int n,k; scanf("%d %d",&n,&k); vector<int> s(k); //每道题的分值 vector<int> q(k); //每道题.

2020-06-05 09:52:15 73

原创 PAT笔记 1070 结绳 (25分)

题目 思路 最长的绳子应折叠次数最少 #include <stdio.h> #include <algorithm> #include <cmath> using namespace std; int main(){ int n; scanf("%d",&n); int arr[n]; for(int i=0;i<n;i++){ scanf("%d",&arr[i]); } .

2020-06-05 09:43:05 107

原创 PAT笔记 1055 集体照 (25分)

题目 #include <iostream> #include <algorithm> #include <vector> using namespace std; struct node { string name; int height; }; int cmp(struct node a, struct node b) { return a.height != b.height ? a.height > b.height : a.n.

2020-06-04 14:34:16 99

原创 PAT笔记 1051 复数乘法 (15分)

题目 思路 按乘法公式对两个复数求积,实部和虚部分开处理、分别输出即可 容易踩坑的地方: 虚部小于0时输出“-”,大于0时输出“+” 实部、虚部的绝对值小于0.005时应直接取0,否则会输出0.00,答案错误 #include <stdio.h> #include <cmath> using namespace std; int main(){ double r1,r2,p1,p2; scanf("%lf %lf %lf %lf",&r1,.

2020-06-04 14:06:47 217

原创 PAT笔记 1064 朋友数 (20分)

题目 思路 输入数字时计算各位之和,把计算得到的和作为数组的下标存入 用数组输出即可~ #include <stdio.h> //求一个数字各位的和 int sum(int n){ int ans=0; do{ ans+=n%10; n/=10; }while(n); return ans; } int main(){ int n,temp; scanf("%d",&n); int .

2020-06-03 22:38:48 83

原创 PAT笔记 1082 射击比赛 (20分)

题目 思路 定义一个结构体person,设置冠军和菜鸟的初始离靶心距离,边输入边更新冠军和菜鸟的id #include <stdio.h> struct person{ int id,x,y; int d; }temp,win,lost; int main(){ int n; scanf("%d",&n); lost.d=0; win.d=10001; for(int i=0;i<n;i++){ .

2020-06-03 21:54:54 109

原创 PAT笔记 1086 就不告诉你 (15分)

题目 思路 把乘积从低位往高位存到数组中,输出即可 容易踩坑的点:初始乘积末尾的连续的0要去掉,不然会出错,比如110*20应该输出22而不是0022 #include <stdio.h> int main(){ int a,b; scanf("%d %d",&a,&b); int mul=a*b; int ans[10]={0},cnt=0; while(mul%10==0){ mul/=10; } .

2020-06-03 18:19:00 108

原创 PAT笔记 1068 万绿丛中一点红 (20分)

题目 思路 用一个二维数组存储输入的像素值,在最外层包裹一圈数值0,方便进行后续的判断 容易踩坑的地方:行和列的输入、使用 #include <stdio.h> #include <algorithm> #include <cmath> #include <map> #include <string.h> using namespace std; int main(){ int m,n,tol,cnt=0; s..

2020-06-03 18:04:13 97

原创 PAT笔记 1083 是否存在相等的差 (20分)

题目 思路 开一个hashTable,下标表示差值,值表示该差值出现的次数,最后从最大的和开始输出值>=2的项就好了~~ #include <stdio.h> #include <cmath> #include <algorithm> using namespace std; int hashTable[10000]={0}; int main(){ int n; scanf("%d",&n); int temp,ma.

2020-06-03 17:03:36 144

原创 PAT笔记 1093 字符串A+B (20分)

题目 思路 用map标记是否出现重复字符,如果字符从未出现过,直接输出 #include <stdio.h> #include <iostream> #include <string> #include <map> using namespace std; int main(){ string str1,str2; getline(cin,str1); getline(cin,str2); map<char,.

2020-06-03 16:51:42 81

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除