pat

浙大pat 1035题解

一笑奈何 提交于 2020-02-20 00:49:34
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords. Input Specification: Each input file contains

1040 有几个PAT

戏子无情 提交于 2020-02-19 13:50:07
分析: PPP A TTTTP A T 第一个A的左边有3个P,右边有5个T,此时PAT共有15个。 第二个A的左边有4个P,右边有1个T,此时PAT共有4个。 这个字符串包含的PAT总共有19个。 总结,只要知道 每个A 的左边共有m个P,右边共有n个T,此时PAT的个数位即为m*n; #include<iostream> using namespace std; typedef long long LL; char a[100010] = {0}; int main() { LL i = 0,cnt_P = 0,cnt_T = 0,ans = 0; while(scanf("%c",&a[i])!=EOF) { if(a[i] == 'T') cnt_T++;//统计T的个数 ++i; } for(LL j = 0; j < i; ++j) { if(a[j] == 'A') ans = (ans+ cnt_P*cnt_T)%1000000007;//注意:ans也要参与运算后再取模 else if(a[j] == 'P') cnt_P++;//统计当前位左边的P的个数 else if(a[j] == 'T') cnt_T--;//统计当前位右边的T的个数 else ; } cout<<ans; return 0; } 来源: https://www.cnblogs.com

适合初步练习PAT乙级——(1074) 宇宙无敌加法器

若如初见. 提交于 2020-02-18 17:16:53
适合初步练习PAT乙级——(1074) 宇宙无敌加法器 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个 PAT 星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是 7 进制数、第 2 位是 2 进制数、第 3 位是 5 进制数、第 4 位是 10 进制数,等等。每一位的进制 d 或者是 0(表示十进制)、或者是 [2,9] 区间内的整数。理论上这个进制表应该包含无穷多位数字,但从实际应用出发,PAT 星人通常只需要记住前 20 位就够用了,以后各位默认为 10 进制。 在这样的数字系统中,即使是简单的加法运算也变得不简单。例如对应进制表“0527”,该如何计算“6203 + 415”呢?我们得首先计算最低位:3 + 5 = 8;因为最低位是 7 进制的,所以我们得到 1 和 1 个进位。第 2 位是:0 + 1 + 1(进位)= 2;因为此位是 2 进制的,所以我们得到 0 和 1 个进位。第 3 位是:2 + 4 + 1(进位)= 7;因为此位是 5 进制的,所以我们得到 2 和 1 个进位。第 4 位是:6 + 1(进位)= 7;因为此位是 10 进制的,所以我们就得到 7。最后我们得到:6203 + 415 = 7201。 输入格式:

PAT 1003 我要通过!

懵懂的女人 提交于 2020-02-17 06:00:24
PAT 1003 我要通过! 答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 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 1.符串中必须仅有 P、 A、 T这三种字符,不可以包含其它字符。 这个很好理解

PAT Advanced 1025 PAT Ranking

别说谁变了你拦得住时间么 提交于 2020-02-16 21:26:54
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank. Input Specification: Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer

PAT B1085 PAT单位排行 (25分)

て烟熏妆下的殇ゞ 提交于 2020-02-16 03:10:01
PAT甲级: B1085 PAT单位排行 (25 分) 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 testees. Then N lines follow, each gives the information of a testee in the following format: ID Score School where ID is a string of 6 characters with the first one representing the test level: B stands for the basic level, A the advanced level and T the top level

PAT乙级算法 1003 我要通过!

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

Count PAT's (25) PAT甲级真题

我的梦境 提交于 2020-02-12 15:25:39
题目分析: 由于本题字符串长度有10^5所以直接暴力是不可取的,猜测最后的算法应该是先预处理一下再走一层循环就能得到答案,所以本题的关键就在于这个预处理的过程,由于本题字符串匹配的内容的固定的PAT,所以我们可以这样想,对于一个输入的串,我们找到每个A的位置,只要知道这个A的前面有几个P,这个A的后面有几个T,就可以得到以这个A为中心的所有种数,二者相乘即可,然后如果我们能得到0~s.size()-1范围内每个A的前面有多少个P,每个A后面有多少个T,只要从头遍历一遍并且求和就能得到最终答案,由于结果可能很大需要MOD 本题代码: 1 #include<iostream> 2 #include<string> 3 #include<string.h> 4 #include<stdio.h> 5 using namespace std; 6 7 const int N = 100005; 8 const int M = 1000000007; 9 int p[N]; 10 int t[N]; 11 12 int main(){ 13 string s; 14 cin>>s; 15 memset(t, 0, sizeof(t)); 16 memset(p, 0, sizeof(p)); 17 int len = s.size(); 18 for(int i = 1; i < len;

【PAT A1060】Are They Equal 编译运行时错误的问题

佐手、 提交于 2020-02-12 14:54:16
PAT A1060 最近刚开始刷PAT甲级的题目,对C++的STL使用不够熟悉,就看《算法笔记》上的相关内容开始学习, 正巧里面穿插了一道PAT的题目,主要与string的使用有关,我就试着做了一下。 写完之后我上传PAT进行测试,发现几个点都是运行时错误, 但是我在这之前已经对书上的几个测试点和网上相关博客提供的测试点进行了测试 答案都是正确的,所以就很郁闷 后面就开始魔改了,浪费了我好多时间, 最后才发现是unsigned int的一个问题,当时为了 匹配 string::npos的类型, 定义了unsigned的类型,但是后面在进行阶数的赋值中,还是不匹配的 但是我还是不太清楚为什么这样会出错,按理说应该达到一定量级,这个问题才会显现出来, 这里N最大100,觉得不会出现这样的问题的。。。orz 有点坑 附上源代码,供大家参考 # include <iostream> # include <string> using namespace std ; int N ; string deal ( string s , int & e ) { string sout ; int flag = 0 ; string :: iterator it = s . begin ( ) ; while ( * it == '0' || * it == '.' ) { if ( * it ==

PAT(乙级) 1040 有几个PAT

删除回忆录丶 提交于 2020-02-12 04:45:12
题目 题目链接 思路 这道题的思路是从网上搜的, -**…… 要想知道构成多少个PAT,那么遍历字符串后对于每一A,它前面的P的个数和它后面的T的个数的乘积就是能构成的PAT的个数。然后把对于每一个A的结果相加即可。辣么就简单啦,只需要先遍历字符串数一数有多少个T,然后每遇到一个T呢cntT–;每遇到一个P呢,cntP++;然后一遇到字母A呢就cntT cntP,把这个结果累加到ans中。最后输出结果,对10000000007取余 原博主 超级优秀的博主链接 代码 # include <iostream> using namespace std ; int main ( ) { string test ; cin >> test ; int cntT = 0 , cntP = 0 , total = 0 ; for ( char e : test ) { if ( e == 'T' ) cntT ++ ; } for ( char e : test ) { if ( e == 'P' ) cntP ++ ; else if ( e == 'T' ) cntT -- ; else total = ( total + ( cntP * cntT ) % 1000000007 ) % 1000000007 ; //else total += cntP*cntT;不能计算到最后才取余