当前位置:网站首页>PTA question bank== > complex four operations, one for one, examination seat number (7-73)
PTA question bank== > complex four operations, one for one, examination seat number (7-73)
2022-07-02 14:30:00 【Name it as father】
One 、 Four operations of complex number
1. Title Description
This question requires the preparation of procedures , Calculation 2 The sum of two plurals 、 Bad 、 product 、 merchant .
2. Input format
Type in a line and press a1 b1 a2 b2
The format of 2 Plural C1=a1+b1i
and C2=a2+b2i
The real part and the virtual part of . Title assurance C2 Not for 0.
3. Output format
Respectively in 4 In line with (a1+b1i) Operator (a2+b2i) = result
Format order output 2 The sum of two plurals 、 Bad 、 product 、 merchant , The number is accurate to the decimal point 1 position . If the real or imaginary part of the result is 0, No output . If the result is 0, The output 0.0.
4. Examples
sample input 1
2 3.08 -2.04 5.06
sample output 1
(2.0+3.1i) + (-2.0+5.1i) = 8.1i
(2.0+3.1i) - (-2.0+5.1i) = 4.0-2.0i
(2.0+3.1i) * (-2.0+5.1i) = -19.7+3.8i
(2.0+3.1i) / (-2.0+5.1i) = 0.4-0.6i
sample input 2
1 1 -1 -1.01
sample output 2
(1.0+1.0i) + (-1.0-1.0i) = 0.0
(1.0+1.0i) - (-1.0-1.0i) = 2.0+2.0i
(1.0+1.0i) * (-1.0-1.0i) = -2.0i
(1.0+1.0i) / (-1.0-1.0i) = -1.0
5. Code section
#include <stdio.h>
#include <stdlib.h>
void Print_same(double a1, double b1, double a2, double b2, char c);
void Print_result(double res1, double res2);
double rounding(double num);
int main()
{
double a1, b1, a2, b2;
scanf("%lf%lf%lf%lf", &a1, &b1, &a2, &b2);
Print_same(a1, b1, a2, b2, '+');
Print_result(rounding(a1 + a2), rounding(b1 + b2));
Print_same(a1, b1, a2, b2, '-');
Print_result(rounding(a1 - a2), rounding(b1 - b2));
Print_same(a1, b1, a2, b2, '*');
Print_result(rounding(a1 * a2 - b1 * b2), rounding(a1 * b2 + a2 * b1));
Print_same(a1, b1, a2, b2, '/');
Print_result(rounding((a1 * a2 + b1 * b2) / (a2 * a2 + b2 * b2)), rounding((-a1 * b2 + a2 * b1) / (a2 * a2 + b2 * b2)));
return 0;
}
void Print_same(double a1, double b1, double a2, double b2, char c) {
if (b1 < 0 && b2 < 0) printf("(%.1lf%.1lfi) %c (%.1lf%.1lfi) = ", a1, b1, c, a2, b2);
else if (b1 < 0) printf("(%.1lf%.1lfi) %c (%.1lf+%.1lfi) = ", a1, b1, c, a2, b2);
else if (b2 < 0) printf("(%.1lf+%.1lfi) %c (%.1lf%.1lfi) = ", a1, b1, c, a2, b2);
else printf("(%.1lf+%.1lfi) %c (%.1lf+%.1lfi) = ", a1, b1, c, a2, b2);
}
void Print_result(double res1, double res2) {
if (res1 == 0 && res2 == 0) printf("0.0\n");
else if (res1 == 0) printf("%.1lfi\n", res2);
else if (res2 == 0) printf("%.1lf\n", res1);
else if (res2 < 0) printf("%.1lf%.1lfi\n", res1, res2);
else printf("%.1lf+%.1lfi\n", res1, res2);
}
double rounding(double num)
{
if (num > 0) num = (int)(num * 10 + 0.5) / 10.0;
else num = (int)(num * 10 - 0.5) / 10.0;
return num;
}
Two 、 One gang, one
1. Title Description
“ A group of students ” It is a common way of learning organization in primary and secondary schools , The teacher put the students who are in the first place and the students who are in the second place . Please write a program to help the teacher finish the assignment automatically , That is, after getting the ranking of the whole class , Among the students who are not currently grouped , Compare the top students with the bottom students opposite sex The students are divided into groups .
2. Input format
Enter the first line to give a positive even number N
(≤50), The number of students in the class . thereafter N
That's ok , Give the gender of each student in the order of ranking from high to low (0 On behalf of girls ,1 On behalf of the boy ) And name ( No more than 8 A non empty string of English letters ), In the meantime 1 Space separation . It is guaranteed that the ratio of men to women in this class is 1:1, And there's no parallel .
3. Output format
Output the names of two students in each line , In the meantime 1 Space separation . The high ranking students are in front , The students with lower rank are in the back . The output order of the group is from the top to the bottom according to the ranking of the students in front .
4. Examples
sample input
8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda
sample output
Amy Jack
Tom Linda
Bill Maya
Cindy John
#include <stdio.h>
struct Student
{
int sex;
char name[9];
};
int main()
{
int n, i, j;
scanf("%d", &n);
struct Student student[n];
for (i = 0; i < n; i++)
{
scanf("%d %s", &student[i].sex, student[i].name);
}
for (i = 0; i < n; i++)
{
for(j = n - 1; j >= i; j--)
{
if (student[i].sex != student[j].sex && student[j].sex != 3)
{
printf("%s %s\n", student[i].name, student[j].name);
student[j].sex = 3;
break;
}
}
}
return 0;
}
3、 ... and 、 Test seat number
1. Title Description
Every PAT Candidates are assigned two seat numbers when they take the exam , One is a test seat , One is the exam seat . Under normal circumstances , Candidates will get the seat number of the test machine before entering , After entering the test state , The system will display the test seat number of the candidate , Candidates need to change their seats during the examination . But some candidates are late , The test run is over , They can only ask you for help with the number of the test seat they have received , Find out their test seat number from the background .
2. Input format
The first line of input gives a positive integer N(≤1000), And then N That's ok , Each line gives a candidate's information : Ticket number Test seat number Test seat number
. among Ticket number
from 16 Digit composition , Seat from 1 To N Number . Input to make sure that everyone's admission number is different , And at no time will two people be assigned to the same seat .
After candidate information , Give a positive integer M(≤N), In the next line M Test seat numbers to be inquired , Space off .
3. Output format
Corresponding to each seat number to be inquired , Output the candidate's pass number and seat number in one line , Intermediate use 1 Space separation .
4. Examples
Input
4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4
Output
3310120150912002 2
3310120150912119 1
5. Code demonstration
#include<stdio.h>
struct Number
{
long a;
int b;
int c;
};
int main()
{
int n;
scanf("%d", &n);
struct Number number[n];
for (int i = 0; i < n; i++) {
scanf("%ld %d %d", &number[i].a, &number[i].b, &number[i].c);
}
int late;
scanf("%d", &late);
int arr2[late];
for (int i = 0; i < late; i++) {
scanf("%d", &arr2[i]);
}
for (int i = 0; i < late; i++) {
for (int j = 0; j < n; j++) {
if (arr2[i] == number[j].b) {
printf("%ld %d\n", number[j].a, number[j].c);
}
}
}
return 0;
}
边栏推荐
- Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
- 你知道Oracle的数据文件大小有上限么?
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
- 腾讯云 TStor 统一存储通过信通院首批文件存储基础能力评测
- Story point vs. Human Sky
- Custom events, global event bus, message subscription and publishing, $nexttick
- How kaggle uses utility script
- PyQt5_QScrollArea内容保存成图片
- 2022 home projector preferred! Dangbei F5 brings the ultimate audio-visual experience with its powerful audio-visual effect
- Golang quickly generates model and queryset of database tables
猜你喜欢
Do you know that there is an upper limit on the size of Oracle data files?
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
Custom events, global event bus, message subscription and publishing, $nexttick
Selenium element positioning method
uniapp自动化测试学习
快解析:轻松实现共享上网
没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
Fabric.js 橡皮擦的用法(包含恢复功能)
每日学习3
随机推荐
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
自定义事件,全局事件总线,消息订阅与发布,$nextTick
Use of freemaker
docker mysql
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
< schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
Fabric.js 缩放画布
Fabric.js 动态设置字号大小
Route (II)
The use of TestNG, the testing framework (II): the use of TestNG XML
跨服务器数据访问的创建链接服务器方法
默认插槽,具名插槽,作用域插槽
The global special paper revenue in 2021 was about $27 million, and it is expected to reach $35 million in 2028. From 2022 to 2028, the CAGR was 3.8%
NLA自然语言分析,让数据分析更智能
Penetrate the remote connection database through the Intranet
每日学习3
无主灯设计:如何让智能照明更加「智能」?
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?