PAT Java 返回非零 的原因 OJ
原因是你写的代码里面的public class后面的那个名字不是Main,改成Main就可以通过了~
1 2 3 4 |
public class Main{ // 此处应为Main public static void main(String[] args){ } } |
- 应该是OJ的规定~
1058. 选择题(20)-PAT乙级真题
批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。
输入格式:
输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过5的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母a开始顺次排列。各项间以1个空格分隔。最后N行,每行给出一个学生的答题情况,其每题答案格式为“(选中的选项个数 选项1 ……)”,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。
输入样例:
3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)
输出样例:
3
6
5
2 2 3 4
分析:n个学生,m道题目。对于每一道题目,将题目的总分存储在total[i]数组里面,将题目的选项插入存储在right[i](为集合类型)里面。wrongCnt[i]存储第i道题错误的人数,对于n个学生,每一个学生的答案插入一个集合st里面,比较st与right[i]是否相等,如果相等说明该生答对了,他的score += total[i](加上当前题目的总分),如果该生答错了,wrongCnt[i]++,表示第i道题新增一个错误的人。输出每一个学生的得分;遍历wrongCnt数组,求wrongCnt的最大值maxWrongCnt。如果maxWrongCnt == 0说明没有一个人做错题目,则输出“Too simple”,否则输出maxWrongCnt的值,和wrongCnt数组中wrongCnt[i] == maxWrongCnt的那些题号~
注意:scanf中的%d和%c之间一定要有分隔符的主动scanf输入,否则可能接收成空格或者空值~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#include <cstdio> #include <vector> #include <set> using namespace std; int main() { int n, m, temp, k; scanf("%d%d", &n, &m); vector<set<char>> right(m); vector<int> total(m), wrongCnt(m); for(int i = 0; i < m; i++) { scanf("%d%d%d", &total[i], &temp, &k); for(int j = 0; j < k; j++) { char c; scanf(" %c", &c); right[i].insert(c); } } for(int i = 0; i < n; i++) { int score = 0; scanf("\n"); for(int j = 0; j < m; j++) { if(j != 0) scanf(" "); scanf("(%d", &k); set<char> st; char c; for(int l = 0; l < k; l++) { scanf(" %c", &c); st.insert(c); } scanf(")"); if(st == right[j]) { score += total[j]; } else { wrongCnt[j]++; } } printf("%d\n", score); } int maxWrongCnt = 0; for(int i = 0; i < m; i++) { if(wrongCnt[i] > maxWrongCnt) { maxWrongCnt = wrongCnt[i]; } } if(maxWrongCnt == 0) printf("Too simple"); else { printf("%d", maxWrongCnt); for(int i = 0; i < m; i++) { if(wrongCnt[i] == maxWrongCnt) { printf(" %d", i + 1); } } } return 0; } |
1057. 数零壹(20)-PAT乙级真题
给定一串长度不超过10^5的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。例如给定字符串“PAT (Basic)”,其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二进制是1000111,即有3个0、4个1。
输入格式:
输入在一行中给出长度不超过105、以回车结束的字符串。
输出格式:
在一行中先后输出0的个数和1的个数,其间以空格分隔。
输入样例:
PAT (Basic)
输出样例:
3 4
分析:用getline接收一行字符串,对于字符串的每一位,如果是字母(isalpha),则将字母转化为大写,并累加(s[i] – ‘A’ + 1)算出n,然后将n转化为二进制,对每一位处理,如果是0则cnt0++,如果是1则cnt1++,最后输出cnt0和cnt1的值~~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <iostream> #include <cctype> #include <string> using namespace std; int main() { string s; getline(cin, s); int n = 0; for(int i = 0; i < s.length(); i++) { if(isalpha(s[i])) { s[i] = toupper(s[i]); n += (s[i] - 'A' + 1); } } int cnt0 = 0, cnt1 = 0; while(n != 0) { if(n % 2 == 0) { cnt0++; } else { cnt1++; } n = n / 2; } printf("%d %d", cnt0, cnt1); return 0; } |
1056. 组合数的和(15)-PAT乙级真题
给定N个非0的个位数字,用其中任意2个数字都可以组合成1个2位的数字。要求所有可能组合出来的2位数字的和。例如给定2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。
输入格式:
输入在一行中先给出N(1<N<10),随后是N个不同的非0个位数字。数字间以空格分隔。
输出格式:
输出所有可能组合出来的2位数字的和。
输入样例:
3 2 8 5
输出样例:
330
分析:用sum统计所有可能组合出来的两位数字之和,在sum累加的过程中,对于每一个输入的数字temp,都能和其他N-1个数字组合出新的数字,temp能够放在个位也能够放在十位,所以每个数字temp都能在个位出现(N-1)次,十位出现(N-1)次,在个位产生的累加效果为temp * (N-1),而在十位产生的累加效果为temp * (N-1) * 10,所以所有数字的累加结果sum即是所有可能组合出来的2位数字的和~
1 2 3 4 5 6 7 8 9 10 11 |
#include <cstdio> int main() { int N, sum = 0, temp; scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", &temp); sum += temp * 10 * (N - 1) + temp * (N - 1); } printf("%d", sum); return 0; } |
【note】PAT甲级题目中的单词整理
randomize 使…随机化
collaborate 合作
gamblers 赌徒
inadequate 不充分的
shuffles 洗牌
casino 赌场
simulate 假装,模拟,模仿
a deck of playing cards 一副牌
Joker 鬼牌
红桃(Heart)、黑桃(Spade)、方片(Diamond)、梅花(Club)
trophy 奖牌,奖杯
Lottery 彩票
distinct 清晰的,明显的,不同的
top-down 自顶向下
decimal 小数
general 通用的,普遍的,普通的
decimal system 十进制 == decimal number
any numeral system 任何进制
notorious 臭名昭著的,声名狼藉的,众人皆知的
suffix 后缀
stuck 动不了的,被卡住的
Deduplication 链表去重
absolute value 绝对值
separate 分开的,独有的,另外的
adjacent 毗连的,邻近的
be supposed to 应该,被期望
exactly 确切地
course 课程
Course List for Student 学生选课情况
alphabetical 按字母顺序
fundamental 基本的,重要的
even 偶数
odd 奇怪的,奇数
hence 因此
recursively 递归
register 注册
specify 具体说明
potential 潜在的
cluster 集群
property 房产,财产
estate 房产
unit price 单价
two-digit number 两位数
For the sake of simplicity 为了简单起见
for every seniority level 对于每一个高层,对于每一层
bonus 奖金,红利,好处
coupon 优惠券
Forbes 福布斯(美国著名财经杂志)
be supposed to 应该,被期望
tie 平局
sequence {A[1], A[2], …} is said to be “smaller” than sequence {B[1], B[2], …} if there exists k >= 1 such that A[i]=B[i] for all i < k, and A[k] < B[k]
如果序列{A[1], A[2], …}与 {B[1], B[2], …},如果存在k>=1,使得对任意的i < k都有A[i] == B[i],而A[k] < B[k]成立,那么就称为方案A比方案B小
ascend 上升 increasing 上升
descend 下降 decreasing 下降
Stripe 条纹,链
distinguish 区分,区别
key words 关键词
Each input file contains one test case. 每一个输入文件包含一个测试用例。
Note: Simple chopping is assumed without rounding. 不用四舍五入
number 数量
It is assumed that 我们假定…
followers 追随者,支持者
Hence 因此
forward 转发
indirect 间接的,拐弯抹角的,迂回的
with positive increments only 只是正向增加
Quadratic probing 二次方探查法
Graduate Admission 研究生入学
respectively 各自地
disjoint 不相交的,脱节,解体
partition 分割,分隔
denote 代表,指示,表示
permutation 一组排列
erase erase erase!!
false FALSE false!!!
volume 容积,量,体积
threshold 起征点,下限,开端
MRI 核磁共振像
M by N matrix m行n列矩阵
quota 限额
for the sake of 为了
scattered cities 分散的城市
recommendation 推荐,建议
candidate 候选的
residential 住宅区
client 委托人,客户,当事人
one-way is 1 if the street is one-way from V1 to V2, or 0 if not
如果该道路是从V1到V2的单行线,则one-way为1,否则为0
fewest intersections 最少结点的
radix 基数,进制,根
intersection 交点,交集