当前位置:网站首页>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;
} 边栏推荐
- Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
- MQ tutorial | exchange (switch)
- 3、函数指针和指针函数
- Generally speaking, if the error of inconsistent tab and space occurs frequently
- 每天坚持20分钟go的基础二
- 默认插槽,具名插槽,作用域插槽
- Pychart connects to the remote server
- Qt新建项目
- MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
- Use of swagger
猜你喜欢

Analysis of CPU surge in production environment service

MQ教程 | Exchange(交换机)

Fabric. JS upper dash, middle dash (strikethrough), underline

Yolov3 & yolov5 output result description

快解析:轻松实现共享上网

Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te

途家木鸟美团夏日折扣对垒,门槛低就一定香吗?

Systemserver process

什么是 eRDMA?丨科普漫画图解

< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621
随机推荐
C语言高级用法--函数指针:回调函数;转换表
Methods of software testing
How kaggle uses utility script
Use of freemaker
[Hongke technology sharing] how to test DNS server: DNS performance and response time test
Fabric. JS upper dash, middle dash (strikethrough), underline
Uniapp automated test learning
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
MQ tutorial | exchange (switch)
故事點 vs. 人天
Multi rotor aircraft control using PID and LQR controllers
Fabric. Keep the original level when JS element is selected
Teamtalk source code analysis win client
Development and design of animation surrounding mall sales website based on php+mysql
Quarkus学习四 - 项目开发到部署
P1908 reverse sequence pair
Qt新建项目
Design of non main lamp: how to make intelligent lighting more "intelligent"?
String matching problem
篇9:XShell免费版安装