当前位置:网站首页>PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
2022-07-02 11:21:00 【名之以父】
一、复数四则运算
1.题目描述
本题要求编写程序,计算2个复数的和、差、积、商。
2.输入格式
输入在一行中按照a1 b1 a2 b2的格式给出2个复数C1=a1+b1i和C2=a2+b2i的实部和虚部。题目保证C2不为0。
3.输出格式
分别在4行中按照(a1+b1i) 运算符 (a2+b2i) = 结果的格式顺序输出2个复数的和、差、积、商,数字精确到小数点后1位。如果结果的实部或者虚部为0,则不输出。如果结果为0,则输出0.0。
4.样例
输入样例1
2 3.08 -2.04 5.06
输出样例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
输入样例2
1 1 -1 -1.01
输出样例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.代码部分
#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;
}
二、一帮一
1.题目描述
“一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的异性学生分为一组。
2.输入格式
输入第一行给出正偶数N(≤50),即全班学生的人数。此后N行,按照名次从高到低的顺序给出每个学生的性别(0代表女生,1代表男生)和姓名(不超过8个英文字母的非空字符串),其间以1个空格分隔。这里保证本班男女比例是1:1,并且没有并列名次。
3.输出格式
每行输出一组两个学生的姓名,其间以1个空格分隔。名次高的学生在前,名次低的学生在后。小组的输出顺序按照前面学生的名次从高到低排列。
4.样例
输入样例
8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda
输出样例
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;
}
三、考试座位号
1.题目描述
每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
2.输入格式
输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:准考证号 试机座位号 考试座位号。其中准考证号由 16 位数字组成,座位从 1 到 N 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。
考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。
3.输出格式
对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。
4.样例
输入
4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4
输出
3310120150912002 2
3310120150912119 1
5.代码演示
#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;
} 边栏推荐
- Essential elements of science fiction 3D scenes - City
- Fabric.js 上划线、中划线(删除线)、下划线
- 删除元素(带过渡动画)
- 跨服务器数据访问的创建链接服务器方法
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- P1042 [noip2003 popularization group] Table Tennis
- [development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
- Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
- Understanding of mongodb
- PyQt5_ Qscrollarea content is saved as a picture
猜你喜欢

Qt新建项目

Fabric. JS free draw circle

HMS core machine learning service helps zaful users to shop conveniently

kaggle如何使用utility script

没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法

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

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

uniapp自动化测试学习

Analysis of CPU surge in production environment service

In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
随机推荐
Teamtalk source code analysis win client
mongodb的认识
Solving the longest subsequence with linear DP -- three questions
Fabric. JS manual bold text iText
Methods of software testing
故事點 vs. 人天
P1908 reverse sequence pair
卷积神经网络(入门)
Launcher startup process
Story points vs. human days
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
Fabric.js 自由绘制圆形
Pychart connects to the remote server
The conference on the growth of all things was held in Hangzhou, and dangbei was selected into the top 100 list of future unicorns in China in 2022
Understanding of mongodb
Codeforces Round #803 (Div. 2)(A~D)
Adhere to the foundation of 20 minutes go every day II
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
一般来讲,如果频繁出现inconsistent tab and space的报错
Multi rotor aircraft control using PID and LQR controllers