pat

PAT乙级1027

感情迁移 提交于 2019-11-26 10:57:50
题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805294251491328 题解 主要有两个内容: 获取第一行(最长行)字符的个数。这个与一般的菱形打印不同,该题的字符不一定用完。 通过循环输出空格与字符(末尾空格就不用输出了) // PAT BasicLevel 1027 // https://pintia.cn/problem-sets/994805260223102976/problems/994805294251491328 #include <iostream> using namespace std; int getLineMaxCount(int maxNum); int main() { // 字符可用数量及字符 int n;char c; cin >> n >> c; // 获取第一行字符的个数 int maxNum = getLineMaxCount(n); // 已输出字符个数 int count=0; // 当前行输出字符个数 int num = maxNum; // 输出上半部分 while(num>1){ // 输出空格 for(int i=0;i<(maxNum-num)/2;++i){ cout << ' '; } // 输出字符 count+=num; for

PAT乙级1028

我怕爱的太早我们不能终老 提交于 2019-11-26 10:57:31
题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805293282607104 题解 这题跟那个德才论(PAT乙级1015)什么的差不多。 因为我用了string和algorithm,所以整个代码实现比较简单。 值得注意的的是,刚开始第3个测试点没过,报错 Segmentation fault 。 网上查题解后,发现还是边界情况的问题(当所有输入都非法时就会数组越界,所以特殊处理一下即可,参考链接:https://blog.csdn.net/daniel960601/article/details/55261196) // PAT BasicLevel 1028 // https://pintia.cn/problem-sets/994805260223102976/problems/994805293282607104 #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class Person{ public: string name; string birthday; Person(string name, string birthday){