
PTA
thats_what_I_thought
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
1004 Counting Leaves c++
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification: Each input file contains one test case. Each case starts with a line containing 0原创 2022-06-04 12:08:09 · 134 阅读 · 0 评论 -
1167 Cartesian Tree c++
A Cartesian tree is a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8, 15, 3, 4, 1, 5, 12, 10, 18, 6 }, the min-heap Cartesia原创 2022-06-04 12:07:18 · 149 阅读 · 0 评论 -
1167 Cartesian Tree c++
A Cartesian tree is a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8, 15, 3, 4, 1, 5, 12, 10, 18, 6 }, the min-heap Cartesia原创 2022-06-03 18:22:08 · 172 阅读 · 0 评论 -
1166 Summit c++
A summit (峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so that everyone is a direct friend of everyone.Now given a set of tentative原创 2022-06-03 17:09:24 · 152 阅读 · 0 评论 -
1165 Block Reversing c++
c++原创 2022-06-03 14:03:08 · 168 阅读 · 0 评论 -
1130 Infix Expression c++
静态二叉树的构造 中序遍历 递归 #include <bits/stdc++.h> using namespace std; #define maxn 30 int n; vector<string>ans; struct node{ string data; int left;int right; }a[maxn]; void init(){ cin>>n; for(int i=1;i<=n;i++){ str原创 2022-05-11 10:45:25 · 238 阅读 · 0 评论 -
1115 Counting Nodes in a BST c++
排二叉树的插入和生成,dfs #include <bits/stdc++.h> using namespace std; struct node{ int data; node *left; node *right; }; map<int,int>result; node *creatnode(int data){ node *temp=new node;; temp->data=data; temp->left=NUL原创 2022-05-10 15:56:43 · 319 阅读 · 0 评论 -
1111 Online Map c++
这奥体就用两次dijkstra算法,两个分开写就行了,两个都是独立的。所以本质上这道题就考的最短路径是否熟练,熟练的话写两次就行了,只是变量太多… #include<bits/stdc++.h> using namespace std; #define maxn 510 int n,m;int source,desti; int Length[maxn][maxn]; int Time[maxn][maxn]; int Lparent[maxn]; int Tparent[maxn]; vect原创 2022-05-09 21:28:37 · 201 阅读 · 0 评论 -
1097 Deduplication on a Linked List c++
#include<bits/stdc++.h> using namespace std; struct node{ int address; int key; int next; }a[100001]; int main(){ node head;cin>>head.next; int n;cin>>n; for(int i=0;i<n;i++){ node temp; cin>>原创 2022-05-08 14:55:13 · 559 阅读 · 0 评论 -
1080 Graduate Admission 结构体排序
#include <bits/stdc++.h> using namespace std; struct student{ int id; float Ge; float Gi; float final; int choice[5]; int rank; }; struct school{ int capacity; //招生容量 vector<student>accept; //最终录取的学生容器 }sch原创 2022-05-06 20:33:06 · 200 阅读 · 0 评论 -
1037 Magic Coupon 实际很简单的一道题
这道题就是从两个数组中取出数据,相乘能使结果最大。开始感觉还挺难的,稍微想一下就知道这道题其实很轻松,并不用什么贪心算法,直接乘就是了。 把每一行给的数据都分成正负两个数组,这样就得到四个数组。 然后给每个四个数组都排序以下 最后把连个正正相乘,两个负负数组相乘就行了 #include <bits/stdc++.h> using namespace std; bool cmp(int a,int b){ return a>b; } int main() { vector&原创 2022-04-27 20:12:45 · 202 阅读 · 0 评论 -
1022 Digital Library (30 分) c++ map查询
这道题就是一个查询问题,查询问题最好的画当然就用map,有一句话说得很好 If you get stuck, try throwing a hashmap at the problem. 根本思路就是在输入的时候就建立对应的map_vector,输出直接遍历就行了。 比如要查询author对应的书籍有哪些,在输入时候就建立map[author]的一个数组,每次这个anthor出现,在他的数组后面新增对应的书籍id就行了 #include <bits/stdc++.h> using names原创 2022-04-25 18:47:41 · 111 阅读 · 0 评论 -
1016 Phone Bills (25 分) 测试点1,2
测试点1,2应该是如果total费用为0的话,不能输出,包括用户名字和月份都不能输出原创 2022-04-22 08:59:01 · 266 阅读 · 0 评论 -
1006 Sign In and Sign Out (25 分)
#include <bits/stdc++.h> using namespace std; bool cmp_early(pair<string,vector<string>>a,pair<string,vector<string>>b){ return a.second[0]<b.second[0]; } bool cmp_late(pair<string,vector<string>>a,pair<.原创 2022-04-19 18:04:57 · 188 阅读 · 0 评论 -
1157 Anniversary (25 分) c++
#include <bits/stdc++.h> using namespace std; bool cmp(string a,string b){ return a.substr(6,8)<b.substr(6,8); } int main(){ int n;cin>>n; unordered_map<string,int>a; //存储校友名单 for(int i=0;i<n;i++){ string原创 2022-04-17 20:02:22 · 635 阅读 · 0 评论 -
1141 PAT Ranking of Institutions (25 分)
#include <bits/stdc++.h> using namespace std; string to_lower(string s){ string temp=""; for(int i=0;i<s.length();i++) temp+= tolower(s[i]); return temp; } class school{ public: string schoolName; float scoreSum=0;原创 2022-04-16 15:28:37 · 92 阅读 · 0 评论 -
1140 Look-and-say Sequence (20 分)
#include <bits/stdc++.h> using namespace std; int main(){ string s;int n; cin>>s>>n; for(int i=0;i<n-1;i++){ string temp=""; for(int j=0;j<s.length();j++){ int count=1; while原创 2022-04-16 14:14:25 · 93 阅读 · 0 评论 -
1128 N Queens Puzzle (20 分) 思路分析
#include <bits/stdc++.h> using namespace std; bool notTongHang(vector<int>a){ //判断有没有同行的元素 set<int>temp; for(int i=0;i<a.size();i++) temp.insert(a[i]); if(temp.size()==a.size()) return true; else .原创 2022-04-14 21:27:52 · 121 阅读 · 0 评论 -
1109 Group Photo (25 分) c++思路分析
#include <bits/stdc++.h> using namespace std; class people{ public: string name; int height; }; bool cmp(people a,people b){ //定义comparator if(a.height==b.height) return a.name<b.name; //如果身高一样,按升序排列 else retu.原创 2022-04-13 10:01:29 · 1127 阅读 · 0 评论 -
1108 Finding Average (20 分)
#include <bits/stdc++.h> using namespace std; bool isNum(string s){ //判断字符串是否是一个数字 bool flag= true; if(s[0]=='-') s=s.substr(1); for(int i=0;i<s.length();i++){ if((s[i]>='0'&&s[i]<='9')||s[i]=='.') .原创 2022-04-12 22:40:57 · 104 阅读 · 0 评论 -
1093 Count PAT‘s (25 分) c++ 思路分析,最后两个测试点
Sample Input: APPAPT Sample Output: 2 首先这道题看运行时间限制就知道肯定不能三重循环暴力求解,最后三个测试点直接运行超时。 于是想减少一层循环,具体思路是:外层循环循环整个字符串,并记录目前已经访问的‘P’的个数,一旦遇到‘A’,开始进入里层循环,里层循环是找当前‘A’往后到结尾的‘T’的个数。然后子串个数’= 左边‘P’的个数 * 右边‘T’的个数 有多少个‘A’,就有多少个 左边‘P’的个数 * 右边‘T’,即可得到答案。 但经过测试,还是会超时。。。 于是就原创 2022-04-11 20:24:33 · 711 阅读 · 0 评论 -
1088 Rational Arithmetic (20 分)
Sample Input 1: 2/3 -4/2 Sample Output 1: 2/3 + (-2) = (-1 1/3) 2/3 - (-2) = 2 2/3 2/3 * (-2) = (-1 1/3) 2/3 / (-2) = (-1/3) Sample Input 2: 5/3 0/6 Sample Output 2: 1 2/3 + 0 = 1 2/3 1 2/3 - 0 = 1 2/3 1 2/3 * 0 = 0 1 2/3 / 0 = Inf 这种题是最不好得分的了,最根本的函数是化原创 2022-04-11 12:23:40 · 105 阅读 · 0 评论 -
1084 Broken Keyboard (20 分) c++
Sample Input: 7_This_is_a_test _hs_s_a_es Sample Output: 7TI 主要用到了tolower(),toupper()函数,和一个数组来记录已经被访问过了字符,下次再遇到一样同一个字符,直接跳过。 #include <bits/stdc++.h> using namespace std; int main(){ string s1,s2; bool hash[128]={0}; getline(cin,s1);原创 2022-04-10 15:42:27 · 715 阅读 · 0 评论 -
1040 Longest Symmetric String (25 分) JAVA
1040 Longest Symmetric String (25 分) JAV解决原创 2022-03-29 11:18:16 · 348 阅读 · 0 评论 -
1043 输出PATest (20 分) Java
给定一个长度不超过 10 4 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 PATestPATest… 这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest 的顺序打印,直到所有字符都被输出。 输入格式: 输入在一行中给出一个长度不超过 10 4 的、仅由英文字母构成的非空字符串。 输出格式: 在一行中按题目要求输出排序后的字符串。题目保证输出非空。 输入样例: redlesPayBestPATTopTeePHPereatitA原创 2021-10-05 19:39:22 · 113 阅读 · 0 评论 -
1037 在霍格沃茨找零钱 (20 分) JAVA实现
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱 P 和他实付的钱 A,你的任务是写一个程序来计算他应该被找的零钱。 输入格式: 输入在 1 行中分别给出 P 和 A,格式为 Galleon.Sickle.Knut,其间用 1 个空格分隔。这里 Galleon 是 [0, 10 7 ] 区间内的整数,Sickle 是 [0, 17) 区间内的整原创 2021-10-02 18:43:42 · 124 阅读 · 0 评论 -
1027 打印沙漏 (20 分) JAVA实现
1027 打印沙漏 (20 分) 本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印 所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。 给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。 输入格式: 输入在一行给出1个正整数N(≤1000)和一个符号,中间以空格分隔。 输出格式: 首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下原创 2021-09-27 16:00:30 · 121 阅读 · 0 评论 -
2021-09-23
1008 数组元素循环右移问题 (20 分) 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A 0 A 1 ⋯A N−1 )变换为(A N−M ⋯A N−1 A 0 A 1 ⋯A N−M−1 )(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法? 输入格式: 每个输入包含一个测试用例,第1行输入N(1≤N≤100)和M(≥0);第2行输入N个整数,之原创 2021-09-23 23:05:13 · 99 阅读 · 0 评论 -
2021-09-23
1007 素数对猜想 让我们定义d n 为:d n =p n+1 −p n ,其中p i 是第i个素数。显然有d 1 =1,且对于n>1有d n 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。 现给定任意正整数N(<10 5 ),请计算不超过N的满足猜想的素数对的个数。 输入格式: 输入在一行给出正整数N。 输出格式: 在一行中输出不超过N的满足猜想的素数对的个数。 输入样例: 20 结尾无空行 输出样例: 4 结尾无空行 JAVA实现: import原创 2021-09-23 21:13:50 · 71 阅读 · 0 评论 -
一对兔子,从出生后第3个月起每个月都生一对兔子。小兔子长到第3个月后每个月又生一对兔子。假如兔子都不死,请问第1个月出生的一对兔子,至少需要繁衍到第几个月时兔子总数才可以达到N对?
输入格式: 输入在一行中给出一个不超过10000的正整数N。 输出格式: 在一行中输出兔子总数达到N最少需要的月数。 输入样例: 30 输出样例: 9 #include <stdio.h> int fibonacci (int n); int main(){ int N,month; scanf("%d",&N); for(month=1;month<=100;month++){ if(fibonacci(month)>=N){ printf("%d",mo原创 2021-04-12 10:11:48 · 903 阅读 · 0 评论 -
本题要求编写程序,打印一个高度为n的、由“*”组成的正菱形图案。
输入格式: 输入在一行中给出一个正的奇数n。 输出格式: 输出由n行星号“*”组成的菱形,如样例所示。每个星号后跟一个空格。 #include <stdio.h> int main(){ int n; scanf("%d",&n); for(int row=1;row<=n/2;row++){ for(int blank=1;blank<=n-1-2*(row-1);blank++){ printf(" "); } for(int star=1;st原创 2021-04-09 22:43:04 · 3171 阅读 · 0 评论 -
皮球从某给定高度自由落下,触地后反弹到原高度的一半,再落下,再反弹,……,如此反复。问皮球在第n次落地时,在空中一共经过多少距离?第n次反弹的高度是多少?
输入格式: 输入在一行中给出两个非负整数,分别是皮球的初始高度和n,均在长整型范围内。 输出格式: 在一行中顺序输出皮球第n次落地时在空中经过的距离、以及第n次反弹的高度,其间以一个空格分隔,保留一位小数。题目保证计算结果不超过双精度范围。 输入样例: 33 5 输出样例: 94.9 1.0 #include <stdio.h> double rebound(long height,long n); int main(){ long height,n; double dis,bounce;原创 2021-04-09 21:18:56 · 6515 阅读 · 0 评论 -
将一笔零钱换成5分、2分和1分的硬币,要求每种硬币至少有一枚,有几种不同的换法?
输入样例: 13 输出样例: fen5:2, fen2:1, fen1:1, total:4 fen5:1, fen2:3, fen1:2, total:6 fen5:1, fen2:2, fen1:4, total:7 fen5:1, fen2:1, fen1:6, total:8 count = 4 #include <stdio.h> int main(){ int x; scanf("%d",&x); int total; int count=0; for(int fe原创 2021-04-09 17:20:51 · 7481 阅读 · 5 评论 -
练习4-6 猜数字游戏 (15 分)
猜数字游戏是令游戏机随机产生一个100以内的正整数,用户输入一个数对其进行猜测,需要你编写程序自动对其与随机产生的被猜数进行比较,并提示大了(“Too big”),还是小了(“Too small”),相等表示猜到了。如果猜到,则结束程序。程序还要求统计猜的次数,如果1次猜出该数,提示“Bingo!”;如果3次以内猜到该数,则提示“Lucky You!”;如果超过3次但是在N(>3)次以内(包括第N次)猜到该数,则提示“Good Guess!”;如果超过N次都没有猜到,则提示“Game Over”,并结原创 2021-04-09 16:35:18 · 299 阅读 · 0 评论 -
本题要求实现一个函数,将两个字符串连接起来。
#include <stdio.h> #include <string.h> #define MAXS 10 char *str_cat( char *s, char *t ); int main() { char *p; char str1[MAXS+MAXS] = {'\0'}, str2[MAXS] = {'\0'}; scanf("%s%s", str1, str2); p = str_cat(str1, str2); prin原创 2021-04-08 12:14:24 · 7293 阅读 · 0 评论 -
习题8-6 删除字符 本题要求实现一个删除字符串中的指定字符的简单函数
#include <stdio.h> #define MAXN 20 void delchar( char *str, char c ); void ReadString( char s[] ); /* 由裁判实现,略去不表 */ int main() { char str[MAXN], c; scanf("%c\n", &c); ReadString(str); delchar(str, c); printf("%s\n", str);原创 2021-04-02 12:54:00 · 5927 阅读 · 0 评论