当前位置:网站首页>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;
} 边栏推荐
- 路由(二)
- 故事點 vs. 人天
- 无主灯设计:如何让智能照明更加「智能」?
- Using computed in uni app solves the abnormal display of data () value in tab switching
- Fabric.js 自由绘制圆形
- Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
- Advanced usage of C language -- function pointer: callback function; Conversion table
- freemarker的使用
- Selenium element positioning method
- 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
猜你喜欢

A white hole formed by antineutrons produced by particle accelerators

The most complete analysis of Flink frame window function

YOLOv3&YOLOv5输出结果说明

<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持

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

测试框架TestNG的使用(二):testNG xml的使用

Method of creating linked server for cross server data access

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

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

Fabric. JS zoom canvas
随机推荐
Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
Fabric.js 动态设置字号大小
PHP linked list creation and traversal
Fabric. JS free draw circle
Selenium element positioning method
篇9:XShell免费版安装
Talk about idempotent design
Fabric.js 橡皮擦的用法(包含恢复功能)
How kaggle uses utility script
Launcher startup process
HMS core machine learning service helps zaful users to shop conveniently
The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
Teamtalk source code analysis win client
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
Basic knowledge of QT original code
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
测试框架TestNG的使用(二):testNG xml的使用
QT new project
uni-app中使用computed解决了tab切换中data()值显示的异常
没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法