春节刷题day3:[PAT乙级:1021 ~ 1030]

2023-11-20 13:38

本文主要是介绍春节刷题day3:[PAT乙级:1021 ~ 1030],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

春节刷题day3:PAT

1021 个位数统计

1022 D进制的A+B

1023 组个最小数

1024 科学计数法

1025 反转链表

1026 程序运行时间

1027 打印沙漏

1028 人口普查

1029 旧键盘

1030 完美数列


1、1021 个位数统计

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
int a[10];
string s;int main(){int i, j, k;while( cin >> s){int len = s.size();for(i = 0; i < len; i++) a[s[i] - '0']++;for(i = 0; i < 10; i++)if(a[i]){printf("%d:%d\n", i, a[i]);break;}for(j = i + 1; j < 10; j++)if(a[j]) printf("%d:%d\n", j, a[j]);}return 0;
}

2、1022 D进制的A+B

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
string s;
long long a, b, c;int main(){int i, j, k;while( cin >> a >> b >> c){a += b;if(!a){ //测试点3卡a = 0, b = 0;cout << a << endl;continue;}while(a){s += a % c + '0'; a /= c;}reverse(s.begin(), s.end());cout << s << endl;}return 0;
}

3、1023 组个最小数

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
int a[10];int main(){int i, j, k;for(i = 0; i < 10; i++) cin >> a[i];for(i = 1; i < 10; i++){if(a[i]){printf("%d", i); a[i]--; break;}}for(i = 0; i < 10; i++){for(j = 0; j < a[i]; j++) printf("%d", i);}puts("");return 0;
}

4、1024 科学计数法

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)using namespace std;const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;int n, m, T;
int l, r, ans;
string s, t, p, q;int main(){int i, j, k;while( cin >> s){int len = s.size();if(s[0] == '-') printf("-");int pos = s.find('E'); t = s.substr(pos + 2);reverse(t.begin(), t.end()); int lent = t.size();for(i = 0, k = 1; i < lent; i++){r += (t[i] - '0') * k; k *= 10;}if(s[pos + 1] == '-'){printf("0.");for(i = 0; i < r - 1; i++) printf("0");for(i = 1; i < pos; i++){if(s[i] == '.') continue;else printf("%c", s[i]);}}else{if(pos - 4 >= r){l = r + 3;for(i = 1; i < pos; i++){if(s[i] == '.') continue;if(i == l) printf(".");printf("%c", s[i]);}}else{for(i = 1; i < pos; i++){if(s[i] == '.') continue;printf("%c", s[i]);}for(i = 0; i < r + 3 - pos; i++) printf("0");}}puts("");}return 0;
}

5、1025 反转链表

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
#define INF 0x7f7f7f7f
#define ull unsigned long long
using namespace std;int N, M, T;
int L, K, tot;
map<int, int> p;
struct node{int add, val, nxt;
}a[maxx + 5];
vector<node> v;void slove(){while(L != -1){int idx = p[L];v.push_back(a[idx]);L = a[idx].nxt;}int tot = v.size();for(int i = 0, cnt = 0; i < tot; i++){cnt++;if(cnt == K){reverse(v.begin() + i + 1 - K, v.begin() + i + 1);cnt = 0;}}for(int i = 0; i < tot - 1; i++)printf("%05d %d %05d\n", v[i].add, v[i].val, v[i + 1].add);printf("%05d %d -1\n", v[tot - 1].add, v[tot - 1].val);
}int main(){int i, j;while(cin >> L >> N >> K){for(i = 0; i < N; i++){cin >> a[i].add >> a[i].val >> a[i].nxt;p[a[i].add] = i;}slove();}return 0;
}

6、1026 程序运行时间

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;int main(){int i, j, k;while(cin >> n >> m){n = (m - n) * 1.0 / 100;if( (m - n) % 100 >= 50) n++;
//		n = ceil( (m - n) * 1.0 / 100);int h = n / 3600;int m = (n - h * 3600) / 60;int s = (n - h * 3600 - m * 60);printf("%02d:%02d:%02d\n", h, m, s);}return 0;
}

7、1027 打印沙漏

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
int cnt;int main(){int i, j, k;char ch;while(cin >> n >> ch){n--;for(i = 3; ; i += 2){if(n < 2 * i) break;n -= 2 * i; cnt++;}for(i = 0; i < cnt; i++){for(j = 0; j < i; j++) printf(" ");for(j = 0; j < 3 + 2 * (cnt - i - 1); j++)printf("%c", ch);puts("");}for(i = 0; i < cnt; i++) printf(" ");printf("%c\n", ch);for(i = 0; i < cnt; i++){for(j = 0; j < cnt - i - 1; j++) printf(" ");for(j = 0; j < 3 + 2 * i; j++)printf("%c", ch);puts("");}cout << n << endl;}return 0;
}

8、1028 人口普查

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
int cnt;
string Min = "1814/09/06";
string Max = "2014/09/06";struct node{string x, y;bool operator < (const node &A)const{return y < A.y;}
}a[maxx + 5];int main(){int i, j, k;while(cin >> n){for(i = 0; i < n; i++){string x, y;cin >> x >> y;if(y >= Min && y <= Max){a[cnt].x = x; a[cnt++].y = y;}}sort(a, a + cnt);if(cnt) cout << cnt << " " << a[0].x << " " << a[cnt - 1].x << endl;else cout << cnt << endl;}return 0;
}

9、1029 旧键盘

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
int cnt;
map<char, bool> p;
string s, t, ans;int main(){int i, j, k;while(cin >> s >> t){int lent = t.size();int lens = s.size();for(i = 0; i < lens; i++){if(s[i] >= 'a' && s[i] <= 'z') s[i] = 'A' + s[i] - 'a';}for(i = 0; i < lent; i++){if(t[i] >= 'a' && t[i <= 'z']) t[i] = 'A' + t[i] - 'a';}for(i = 0; i < lent; i++) p[t[i]] = true;for(i = 0; i < lens; i++){if(!p[s[i]]){ans += s[i]; p[s[i]] = true;}}cout << ans << endl;}return 0;
}

10、1030 完美数列

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
#define INF 0x7f7f7f7fusing namespace std;long long n, m, T;
long long a[maxx + 5];int main(){int i, j, k;while(cin >> n >> m){int ans = -1;for(i = 0; i < n; i++) cin >> a[i];sort(a, a + n); a[n] = INF;for(i = 0; i < n; i++){T = m * a[i];k = upper_bound(a, a + n, T) - a;ans = max(ans, k - i);}cout << ans << endl;}return 0;
}

2021/2/8完结(今天结束的稍微早点,刷题过程中主要是有些坑点让人头大,要是自己能够考虑全面就好了)。

这篇关于春节刷题day3:[PAT乙级:1021 ~ 1030]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/394991

相关文章

【每日刷题】Day113

【每日刷题】Day113 🥕个人主页:开敲🍉 🔥所属专栏:每日刷题🍍 🌼文章目录🌼 1. 91. 解码方法 - 力扣(LeetCode) 2. LCR 098. 不同路径 - 力扣(LeetCode) 3. 63. 不同路径 II - 力扣(LeetCode) 1. 91. 解码方法 - 力扣(LeetCode) //思路:动态规划。 cl

hot100刷题第1-9题,三个专题哈希,双指针,滑动窗口

求满足条件的子数组,一般是前缀和、滑动窗口,经常结合哈希表; 区间操作元素,一般是前缀和、差分数组 数组有序,更大概率会用到二分搜索 目前已经掌握一些基本套路,重零刷起leetcode hot 100, 套路题按套路来,非套路题适当参考gpt解法。 一、梦开始的地方, 两数之和 class Solution:#注意要返回的是数组下标def twoSum(self, nums: Lis

代码随想录刷题day25丨491.递增子序列 ,46.全排列 ,47.全排列 II

代码随想录刷题day25丨491.递增子序列 ,46.全排列 ,47.全排列 II 1.题目 1.1递增子序列 题目链接:491. 非递减子序列 - 力扣(LeetCode) 视频讲解:回溯算法精讲,树层去重与树枝去重 | LeetCode:491.递增子序列_哔哩哔哩_bilibili 文档讲解:https://programmercarl.com/0491.%E9%80%92%E

代码随想录刷题day24丨93.复原IP地址 ,78.子集 , 90.子集II

代码随想录刷题day24丨93.复原IP地址 ,78.子集 , 90.子集II 1.题目 1.1复原IP地址 题目链接:93. 复原 IP 地址 - 力扣(LeetCode) 视频讲解:回溯算法如何分割字符串并判断是合法IP?| LeetCode:93.复原IP地址_哔哩哔哩_bilibili 文档讲解:https://programmercarl.com/0093.%E5%A4%8

【笔记】数据结构刷题09

快速排序 215. 数组中的第K个最大元素 class Solution {public:int findKthLargest(vector<int>& nums, int k) {return divide(nums,0,nums.size()-1,nums.size()-k);}int divide(vector<int>& nums,int left,int right,int k)

C语言:刷题日志(1)

一.阶乘计算升级版 本题要求实现一个打印非负整数阶乘的函数。 其中n是用户传入的参数,其值不超过1000。如果n是非负整数,则该函数必须在一行中打印出n!的值,否则打印“Invalid input”。 首先,知道阶乘是所有小于及等于该数的正整数的积,并且0的阶乘为1。那么我们先来个简单的阶乘计算吧。 #include<stdio.h>int Fact(int n){if (n <=

【每日刷题】Day112

【每日刷题】Day112 🥕个人主页:开敲🍉 🔥所属专栏:每日刷题🍍 🌼文章目录🌼 1. 1137. 第 N 个泰波那契数 - 力扣(LeetCode) 2. 面试题 08.01. 三步问题 - 力扣(LeetCode) 3. LCR 088. 使用最小花费爬楼梯 - 力扣(LeetCode) 1. 1137. 第 N 个泰波那契数 - 力扣(LeetCo

【数据结构】【java】leetcode刷题记录--链表

简介 链表是一种常见的基础数据结构,它由一系列节点组成,每个节点包含数据域和指向下一个节点的指针。在Java中,链表通常用于实现动态数据结构,因为它可以根据需要动态地增加或减少节点。 链表简介: 节点结构:链表中的每个元素称为节点(Node),每个节点包含两部分:数据域(存储数据)和指针域(存储下一个节点的地址)动态性:链表的长度不是固定的,可以根据需要动态地增减节点。内存分配:链表中的节点

PAT甲级-1044 Shopping in Mars

题目   题目大意 一串项链上有n个钻石,输入给出每个钻石的价格。用m元买一个连续的项链子串(子串长度可为1),如果不能恰好花掉m元,就要找到最小的大于m的子串,如果有重复就输出多个,按递增顺序输出子串的前端和后端索引。 原来的思路 取连续的子串使和恰等于m,没有恰等于就找最小的大于。可以将子串依次累加,使得每个位置都是起始位置到该位置的序列和,整个数组显递增顺序,就可以用右边减左边

PAT (Advanced Level) Practice——1011,1012

1011:  链接: 1011 World Cup Betting - PAT (Advanced Level) Practice (pintia.cn) 题意及解题思路: 简单来说就是给你3行数字,每一行都是按照W,T,L的顺序给出相应的赔率。我们需要找到每一行的W,T,L当中最大的一个数,累乘的结果再乘以0.65,按照例子写出表达式即可。 同时还需要记录每一次选择的是W,T还是L