1018. 可被 5 整除的二进制前缀 发表于 2021-01-14 分类于 programming , algorithm-practice , leetcode 本文字数: 40 阅读时长 ≈ 1 分钟找规律题1234567891011121314151617class Solution {public: vector<bool> prefixesDivBy5(vector<int>& A) { vector<bool> ret; int res = 0; for(auto&&a:A){ res = res * 2 + a; res %= 10; if(res % 5 == 0){ ret.push_back(true); }else{ ret.push_back(false); } } return ret; }};
1035. Password 发表于 2021-01-13 分类于 programming , algorithm-practice , PTA 本文字数: 104 阅读时长 ≈ 1 分钟水题123456789101112131415161718192021222324252627282930313233343536#include <iostream>#include <sstream>using namespace std;int main(){ int n; cin >> n; int mod = 0; ostringstream out; for (int i = 0; i < n; i++) { string name, pass; int flag = 0; cin >> name >> pass; for (auto &&ch : pass) { switch (ch) { case 'l': ch = 'L'; flag = 1; break; case '1': ch = '@'; flag = 1; break; case '0': ch = '%'; flag = 1; break; case 'O': ch = 'o'; flag = 1; break; default: break; } } if (flag) { mod++; out << name << " " << pass << endl; } } if (mod) { cout << mod << endl << out.str(); } else { cout << "There " << (n == 1 ? "is" : "are") << " " << n << " account" << (n == 1 ? "" : "s") << " and no account is modified" << endl; } return 0;}
684. 冗余连接 发表于 2021-01-13 分类于 programming , algorithm-practice , leetcode 本文字数: 123 阅读时长 ≈ 1 分钟#思路有环无向图中找出环上最后出现的边
1203. 项目管理 发表于 2021-01-12 分类于 programming , algorithm-practice , leetcode 本文字数: 73 阅读时长 ≈ 1 分钟双重拓扑排序: 组内 & 组间拓扑排序
1151. LCA in a Binary Tree 发表于 2021-01-12 分类于 programming , algorithm-practice , PTA 本文字数: 305 阅读时长 ≈ 1 分钟二叉树上寻找最近公共祖先需要注意节点的key不一定连续
1036. Boys vs Girls 发表于 2021-01-11 分类于 programming , algorithm-practice , PTA 本文字数: 100 阅读时长 ≈ 1 分钟送分题123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include <iostream>using namespace std;struct student { string name; string major;};int main(){ int n; cin >> n; student s, male_min, female_max; int score, male_score_min = 101, female_score_max = -1; string gender; for (int i = 0; i < n; i++) { cin >> s.name >> gender >> s.major >> score; if (gender == "M") { if (score < male_score_min) { male_min = s; male_score_min = score; } } else { if (score > female_score_max) { female_max = s; female_score_max = score; } } } if (female_score_max != -1) { cout << female_max.name << " " << female_max.major << endl; } else { cout << "Absent" << endl; } if (male_score_min != 101) { cout << male_min.name << " " << male_min.major << endl; } else { cout << "Absent" << endl; } if (female_score_max != -1 && male_score_min != 101) { cout << female_score_max - male_score_min << endl; } else { cout << "NA" << endl; } return 0;}
1202. 交换字符串中的元素 发表于 2021-01-11 分类于 programming , algorithm-practice , leetcode 本文字数: 243 阅读时长 ≈ 1 分钟#题意给定一些可以任意交换位置的组, 求整个字符串的最小字典序
1093. Count PAT's 发表于 2021-01-10 分类于 programming , algorithm-practice , PTA 本文字数: 128 阅读时长 ≈ 1 分钟#题意计算PAT字串个数
1140. Look-and-say Sequence 发表于 2021-01-10 分类于 programming , algorithm-practice , PTA 本文字数: 95 阅读时长 ≈ 1 分钟#题意求一个数字用行程编码压缩n-1次的结果