pat

PAT A1075 20200119

删除回忆录丶 提交于 2020-01-26 00:35:20
PAT A1075 20200119 第一次使用csdn,开始记录PAT刷题 类型:排序题目 注意点:读题一定要仔细,排序的时候,理清楚排序的先后 首先就是学生数据的初始化,需要对学生的学号和相关的信息进行初始化,不可以一边输入,一遍初始化。不然会一部分学生的信息不存在。 其次,就是学生多次提交的问题,只记录最高分,因此可能多次提交完美答案,因此需要输入完毕之后,计算有几个完美解答的题目。 最后,有关输出不显示的问题,不显示的是没有提交能够通过编译的学生或者根本没有提交解答的学生,需要注意的是记录中0和-1的区别。 最最关键的是 最后所有都考虑在内的时候,还有一个没有注意到,就是在一个记录输入为-1的时候,没有判断之前的成绩是否为-1,又改了原来的成绩。 #include < iostream > #include < stdlib . h > #include < queue > #include < stack > #include < algorithm > #include < map > #include < cstring > using namespace std ; typedef struct { int num , sum = 0 , perfectNum = 0 , rank , flag = 0 ; int score [ 6 ] = { - 1 , - 1

P1040 有几个PAT

独自空忆成欢 提交于 2020-01-24 22:32:44
转跳点: 🐏 1040 有几个PAT (25分) 字符串 APPAPT 中包含了两个单词 PAT ,其中第一个 PAT 是第 2 位( P ),第 4 位( A ),第 6 位( T );第二个 PAT 是第 3 位( P ),第 4 位( A ),第 6 位( T )。 现给定字符串,问一共可以形成多少个 PAT ? 输入格式: 输入只有一行,包含一个字符串,长度不超过 1,只包含 P 、 A 、 T 三种字母。 输出格式: 在一行中输出给定字符串中包含多少个 PAT 。由于结果可能比较大,只输出对 1000000007 取余数的结果。 输入样例: APPAPT 输出样例: 2   这道题,和之前的我要通过一样属于,烧脑题,代码极简。我可怜的头发。 (在写分析之前先写一下规定,P的个数:Pcount;PA的个数:PAcounT,PAT的个数:PATcount,) 我第一轮分析如下:   随便写了一个样例,写出了所有可能,得出一些结论:     1、发现PAT的个数取决于PA个数     2、PA个数取决于P个数 第二次分析:   统计了一下每个A前面P的 Pcount,发现每个A对应的 PAcount 是 A 之前的Pcount的数量   统计了一下每个T前面的PA的 PAcount,发现每个T对应的PATcount是T之前所有A对应的PAcount的累加  

【PAT】A1141 PAT Ranking of Institutions (25point(s))

强颜欢笑 提交于 2020-01-24 12:54:19
文章目录 A1141 PAT Ranking of Institutions (25point(s)) Input Specification: Output Specification: Sample Input: Sample Output: Code Analysis Author: CHEN, Yue Organization: 浙江大学 Time Limit: 800 ms Memory Limit: 64 MB Code Size Limit: 16 KB A1141 PAT Ranking of Institutions (25point(s)) After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integer N (≤10^​5​​ ), which is the number of

PAT Advanced 1093 Count PAT's (25分)

拟墨画扇 提交于 2020-01-20 01:52:18
The string APPAPT contains two PAT 's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters. Now given any string, you are supposed to tell the number of PAT 's contained in the string. Input Specification: Each input file contains one test case. For each case, there is only one line giving a string of no more than 1 characters containing only P , A , or T . Output Specification: For each test case, print in one line the number of PAT 's contained in the string. Since the result may be a huge

PAT乙级题库 1003 我要通过!

守給你的承諾、 提交于 2020-01-18 14:47:07
1003 我要通过! (20分) “答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。 得到“答案正确”的条件是: 字符串中必须仅有 P 、 A 、 T 这三种字符,不可以包含其它字符; 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串; 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a 、 b 、 c 均或者是空字符串,或者是仅由字母 A 组成的字符串。 现在就请你为 PAT 写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。 输入格式: 每个测试输入包含 1 个测试用例。第 1 行给出一个正整数 n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过 100,且不包含空格。 输出格式: 每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出 YES ,否则输出 NO 。 输入样例: 8 PAT PAAT AAPATAA AAPAATAAAA xPATx PT Whatever APAAATAA 输出样例: YES YES YES YES NO NO NO NO 解题思路: 第一条规则规定了输入的字符串中只能含有P、A

Day42: [PAT甲级] 1015 Reversible Primes (20分)

匆匆过客 提交于 2020-01-16 08:20:55
Day42: [PAT甲级] 1015 Reversible Primes (20分) 题源: 来自PAT甲级题库: https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 代码: dirty code凑合看吧 三种函数要熟练:其他进制转10进制;10进制转其他进制;判断素数 # include <iostream> # include <string> # include <vector> # include <cstdio> # include <algorithm> using namespace std ; int N , D ; string ten_D_re ( int N , int D ) ; long long D_ten_re ( string N , int D ) ; bool isprime ( long long X ) ; int main ( ) { while ( cin >> N ) { if ( N < 0 ) break ; cin >> D ; //cout << "!" << N << " " << D << endl; if ( ! isprime ( N ) ) { cout << "No" << endl ; continue ; }

Day41: [PAT甲级] 1013 Battle Over Cities (25分)

拟墨画扇 提交于 2020-01-15 06:13:28
Day41: [PAT甲级] 1013 Battle Over Cities (25分) 题源: 来自PAT真题库: https://pintia.cn/problem-sets/994805342720868352/problems/994805500414115840 代码: dirty code凑合看吧 ps.还有一种并查集的思路。但是要注意 路径压缩 ! pps.这道题我最先用邻接矩阵+BFS的方法,有一个用例超时了。后来发现是因为自己有个地方搞错了,BFS是入队时就要进行访问,不是出队! # include <iostream> # include <string> # include <vector> # include <queue> # include <cstdio> # include <algorithm> using namespace std ; int N , M , K ; int x , y ; vector < vector < int > > V ; vector < bool > collected ; void DFS ( int X ) { collected [ X ] = true ; for ( int i = 1 ; i <= N ; i ++ ) { if ( V [ X ] [ i ] == 1 && i != x &&

Bash脚本编程之字符串处理

非 Y 不嫁゛ 提交于 2020-01-15 03:47:19
简介 其实这里说得字符串处理,对应的是bash官网中的 【Shell Parameter Expansion】 ,不过直接去看这部分内容实在是太难以理解了。字符串处理会比较好理解,平常使用应该也是足够的了。 字符串切片 这块在上一篇讲解数组的文章中 Bash脚本编程之数组 ,也大概提到了Shell Parameter Expansion除了可以对数组(array)切片以外,还可以对变量切片。 ${var:offset:number} ${var: length} [ root@c7-server ~ ] # name="zhangwenlong" [ root@c7-server ~ ] # echo ${name} zhangwenlong [ root@c7-server ~ ] # echo ${name:2:5} angwe [ root@c7-server ~ ] # echo ${name: -4} long 基于pattern取子串 这里的pattern,应该是glob或者类glob的,而非正则表达式,详见官方的 Pattern Matching 。 ${var#*pattern}:在变量var的值中自左向右查询pattern,若查询到,则删除值首部至第一次出现的pattern之间的所有字符。 [ root@c7-server ~ ] # echo ${name}

PAT Advanced level 1001 A+B Format

怎甘沉沦 提交于 2020-01-13 18:11:43
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Specification: Each input file contains one test case. Each case contains a pair of integers a and b where −. The numbers are separated by a space. Output Specification: For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format. Sample Input: -1000000 9 Sample Output: -999,991 虽然放假了但是并不能愉快划水qwq嗯,因为作死报了个PAT于是现在开始刷PAT的题了。。。希望开学前能刷完吧(大概第一题,原来a+b还能出成这样。。。计算一下数字位数

PAT甲级1050

佐手、 提交于 2020-01-13 08:47:22
#PAT甲级1050 讲述的主要是字符串处理,可以使用map解决 #include < iostream > #include < cstring > #include < algorithm > #include < map > using namespace std ; string s1 , s2 ; int main ( ) { getline ( cin , s1 ) ; getline ( cin , s2 ) ; map < char , int > m ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) { m [ s2 [ i ] ] = 1 ; } for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( m [ s1 [ i ] ] == 0 ) { cout << s1 [ i ] ; } } return 0 ; } /* They are students. aeiou */ 来源: CSDN 作者: 这是小卢呀 链接: https://blog.csdn.net/qq_41581913/article/details/103940129