PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目
1009 Product of Polynomials (25 point(s))
This time, you are supposed to find A×B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
K N1 aN1 N2 aN2 ... NK aNK
where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤NK<⋯<N2<N1≤1000.
Output Specification:
For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.
Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 3 3.6 2 6.0 1 1.6
这道题的意思是让两个多项式相乘。
做这道题的时候我吸取前面的教训,直接用的数组。就是按照数学中怎么多项式相乘的。
#include<cstdio>
#include<cstring> int main()
{
double a[], b[], c[];//分别存多项式指数以及系数
int n, temp_N;
memset(a, , * sizeof(double));
memset(b, , * sizeof(double));
memset(c, , * sizeof(double));
double temp_aN;
scanf("%d", &n);
while (n--) {
scanf("%d %lf", &temp_N, &temp_aN);
a[temp_N] = temp_aN;
}
scanf("%d", &n);
while (n--) {
scanf("%d%lf", &temp_N, &temp_aN);
b[temp_N] = temp_aN;
} //相乘
for (int i = ;i < ;i++) {
for (int j = ;j < ;j++) {
c[i + j] += a[i] * b[j];
}
}
//数数有几项
int count = ;
for (int i = ;i >=;i--) {
if (c[i] != ) count++;
}
printf("%d", count);
for (int i = ;i >= ;i--) {
if (c[i] != ) printf(" %d %.1lf",i,c[i]);
}
return ;
}
我感觉挺复杂的。遍历了所有元素。
不过。。。牛客和PATOJ都过了,也没说超时。
我看了书上的答案后,他的比我的简单,他是在输入第二个多项式的同时,嵌套一个循环去相乘。
其他的都差不多。还是得活学活用呀。
1041 考试座位号 (15 point(s))
每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
输入格式:
输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:
准考证号 试机座位号 考试座位号
。其中准考证号
由 14 位数字组成,座位从 1 到 N 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。
输出格式:
对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。
输入样例:
4
10120150912233 2 4
10120150912119 4 1
10120150912126 1 3
10120150912002 3 2
2
3 4
输出样例:
10120150912002 2
10120150912119 1
#include<cstdio>
struct Student {
long long ID;
int tryNum;
int examNum;
}data[];
int main() {
int n,m,i;
scanf("%d", &n);
for (i = ;i < n;i++) scanf("%lld%ld%ld", &data[i].ID, &data[i].tryNum, &data[i].examNum);
scanf("%d", &m);
for (i = ;i < m;i++) {
int find_tryNum;
scanf("%d", &find_tryNum);
for (int j = ;j < n;j++) {
if (data[j].tryNum == find_tryNum) printf("%lld %d\n", data[j].ID, data[j].examNum);
}
}
return ;
}
这道题很简单。但我看了教材的算法之后,发现可以直接令结构体的下标为试机座位。不用遍历一下去找了。
笨死了。
1004 成绩排名 (20 point(s))
读入 n(>0)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。
输入格式:
每个测试输入包含 1 个测试用例,格式为
第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩
... ... ...
第 n+1 行:第 n 个学生的姓名 学号 成绩
其中
姓名
和学号
均为不超过 10 个字符的字符串,成绩为 0 到 100 之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。输出格式:
对每个测试用例输出 2 行,第 1 行是成绩最高学生的姓名和学号,第 2 行是成绩最低学生的姓名和学号,字符串间有 1 空格。
输入样例:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
输出样例:
Mike CS991301
Joe Math990112
#include<cstdio>
#include<cstring> int main(){
char max_name[],min_name[],max_ID[],min_ID[],temp_name[],temp_ID[];
int n,max_score=, min_score=,temp_score;
scanf("%d", &n);
while (n--)
{
scanf("%s%s%d", temp_name, temp_ID, &temp_score);
if (temp_score > max_score) {
max_score = temp_score;
strcpy(max_name, temp_name);
strcpy(max_ID, temp_ID);
}
if (temp_score < min_score) {
min_score = temp_score;
strcpy(min_name, temp_name);
strcpy(min_ID, temp_ID);
}
}
printf("%s %s\n", max_name, max_ID);
printf("%s %s\n", min_name, min_ID);
return ;
}
这个我为啥没想到用结构体。。。那么傻的建立了那么多字符数组,唉。。。。
PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名的更多相关文章
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲级——1009 Product of Polynomials
PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT 乙级 1041 考试座位号(15) C++版
1041. 考试座位号(15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 每个PAT考生在参加考试时都会被分 ...
- PAT乙级-1041. 考试座位号(15)
每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座 ...
- PAT (Basic Level) Practice (中文)1041 考试座位号 (15 分)
每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考 ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
随机推荐
- 【转】Android开发学习笔记(一)——初识Android
对于一名程序员来说,“自顶向下”虽然是一种最普通不过的分析问题和解决问题的方式,但其却是简单且较为有效的一种.所以,将其应用到Android的学习中来,不至于将自己的冲动演变为一种盲目和不知所措. 根 ...
- 几乎零配置产生Nuget包的库:White Tie
通过Nuget管理器为你所需要产生Nuget包的项目安装White Tie,目前最新版本为1.3.16,VS2015下可用,VS2013应该问题也不大,VS2010就不好说了. 安装好之后直接重新生成 ...
- Spring Security 之Session管理配置
废话不多说,直接上代码.示例如下: 1. 新建Maven项目 session 2. pom.xml <project xmlns="http://maven.apache.o ...
- 怎么让Sublime Text不自动打开最近的文件/项目
"hot_exit": false,"remember_open_files": false,
- Android 最新学习资料收集
收集这份资料的灵感来源于我的浏览器收藏夹快爆了,后来在github 上也看到了很优秀的开源库的收集资料,非常的好,但是太过于多,也不够新,所以决定自己来做一个.原始的markdowm文件已经放到git ...
- ES6初识-Symbol
Symbol的概念 变量是独一无二的 let a1=Symbol(); let a2=Symbol(); a1和a2严格意义不相等 let a3=Symbol.for('a3'); let a4=Sy ...
- gdb-pada调试实例
先编写个简单的hello的程序 hello.c (ps:有没有头文件行不行,试试不就知道了) int main(){ printf("hello!\n"); int m,n; in ...
- Hive的数据库和表
本文介绍一下Hive中的数据库(Database/Schema)和表(Table)的基础知识,由于篇幅原因,这里只是一些常用的.基础的. Hive的数据库和表 先看一张草图: Hive结构 从图上可以 ...
- 编辑工具_vi
vi/vim平时经常会用到,但是一直没有时间系统的整理下,今天看到了一篇不错的介绍文章.引用下,就当做笔记了,但是不晓得该怎么填引用路径,如有侵权请告知,补上引用路径 01. vi 简介 1.1 学习 ...
- [USACO5.1]夜空繁星Starry Night
题目背景 高高的星空,簇簇闪耀的群星形态万千.一个星座(cluster)是一群连通的星组成的非空连通星系,这里的连通是指水平,垂直或者对角相邻的两个星星.一个星座不能是另一个更大星座的一部分, 星座可 ...