当前位置:网站首页>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;
} 边栏推荐
- 软件测试的方法
- Uniapp automated test learning
- Pycharm连接远程服务器
- php链表创建和遍历
- 3、函数指针和指针函数
- Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
- c# 水晶报表打印
- <口算練習機 方案開發原理圖>口算練習機/口算寶/兒童數學寶/兒童計算器 LCD液晶顯示驅動IC-VK1621B,提供技術支持
- P1042 [NOIP2003 普及组] 乒乓球
- 一般来讲,如果频繁出现inconsistent tab and space的报错
猜你喜欢

The most complete analysis of Flink frame window function

Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'

Do you know that there is an upper limit on the size of Oracle data files?

A white hole formed by antineutrons produced by particle accelerators

C crystal report printing
![[to be continued] [UE4 notes] l5ue4 model import](/img/6b/d3083afc969043dbef1aeb4fccfc99.jpg)
[to be continued] [UE4 notes] l5ue4 model import

PHP linked list creation and traversal

TeamTalk源码分析之win-client

万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单

YOLOv3&YOLOv5输出结果说明
随机推荐
Launcher startup process
Fabric.js 元素被选中时保持原有层级
Yyds dry goods inventory software encryption lock function
Fabric. JS manual bold text iText
String matching problem
How kaggle uses utility script
P1908 逆序对
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
数据湖(十一):Iceberg表数据组织与查询
uniapp自动化测试学习
Stm32-dac Experiment & high frequency DAC output test
无主灯设计:如何让智能照明更加「智能」?
一般来讲,如果频繁出现inconsistent tab and space的报错
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
Whole house Wi Fi: a pain point that no one can solve?
Understanding of mongodb
Pycharm连接远程服务器
Teamtalk source code analysis win client
Fabric. JS dynamically set font size
Openharmony notes --------- (4)