网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
#include<bits/stdc++.h>
using namespace std;
struct shibin{
char name[1005],tool[1005];
int force;
}shi[3];
int main( )
{
for(int i=0;i<2;i++){
cin>>shi[i].name>>shi[i].tool>>shi[i].force;
}
if(shi[0].force>=shi[1].force){
cout<<shi[0].name<<" "<<shi[0].tool<<" "<<shi[0].force<<endl;
cout<<shi[1].name<<" "<<shi[1].tool<<" "<<shi[1].force;
}else{
cout<<shi[1].name<<" "<<shi[1].tool<<" "<<shi[1].force<<endl;
cout<<shi[0].name<<" "<<shi[0].tool<<" "<<shi[0].force;
}
return 0;
}
12. MT1562 谁是先锋
(1)题目描述
攻城战要开始了,女王依依手里有4个黑骑士,女王依依要找出最强大的黑骑士作为先锋。
请设计一个结构体,管理他们的信息,信息包括姓名,攻击力。
输入他们信息,然后再输出先锋的信息。
格式
输入格式:输入分4行,姓名为字符型,攻击力整型
.
输出格式: 输出分4行
样例1
输入格式:
Mike 200
Molly 355
Tom 199
Nana 290
.
输出格式: Molly 355
备注:
各黑骑士攻击力唯一,且均为正数。
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct shibin{
char name[1005];
int force;
}shi[5];
int main( )
{
for(int i=0;i<4;i++){
cin>>shi[i].name>>shi[i].force;
}
int maxx=shi[0].force,index=0;
for(int i=1;i<4;i++){
if(shi[i].force>maxx){
maxx=shi[i].force;
index = i;
}
}
cout<<shi[index].name<<" "<<shi[index].force<<endl;
return 0;
}
13. MT1563 谁是胆小鬼
(1)题目描述
攻城战结束了,女王依依清点俘虏,发现跑掉了1个胆小的穴居人,女王依依要找出是谁跑掉了。斥候调查发现逃走的是一个攻击力最弱小的穴居人。
请设计一个结构体,管理穴居人俘虏的信息,信息包括姓名,攻击力。
输入4个俘虏的信息,然后再输出逃走的俘虏的信息。
格式
输入格式: 输入分4行,姓名为字符型,攻击力整型
.
输出格式: 输出分4行
样例1
输入格式:
Mike 20
Molly 13
Tom 11
Nana 29
.
输出格式: Tom 11
备注:
各穴居人攻击力唯一,且均为正数。
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct shibin{
char name[1005];
int force;
}shi[5];
int main( )
{
for(int i=0;i<4;i++){
cin>>shi[i].name>>shi[i].force;
}
int minn=shi[0].force,index=0;
for(int i=1;i<4;i++){
if(shi[i].force<minn){
minn=shi[i].force;
index = i;
}
}
cout<<shi[index].name<<" "<<shi[index].force<<endl;
return 0;
}
14. MT1564 编程好难
(1)题目描述
小码哥买了3本编程书,他想先学最简单的,请帮他把最薄的书挑出来。请设计一个结构体,管理书籍的信息,信息包括种类,书名(不含空格),页数。输入书籍的信息,然后再输出最薄的书信息。
格式
输入格式: 按行输入种类,书名为字符型,价格整型
.
输出格式: 按行输出种类,书名为字符型,价格整型
样例1
输入格式:
c cprimer 500
java hijava 300
c cbeginner 230
.
输出格式: c cbeginner 230
备注:
书的页数唯一,且均为正数。
(2)参考代码
#include<stdio.h>
struct Book {
char typical[10];
char book[50];
int page;
};
struct Book bookneed[100];
int main()
{
int i,j;
for(i=1;i<=3;i++){
scanf("%s",&bookneed[i].typical);
scanf("%s",&bookneed[i].book);
scanf("%d",&bookneed[i].page);
}
for(i=1;i<=3;i++){
for(j=1;j<=3-i;j++) {
if (bookneed[j + 1].page < bookneed[j].page) {
bookneed[0] = bookneed[j+1];
bookneed[j + 1] = bookneed[j];
bookneed[j] = bookneed[0];
}
}
}
printf("%s %s %d",bookneed[1].typical,bookneed[1].book,bookneed[1].page);
return 0;
}
15. MT1565 长者
(1)题目描述
输出结构体数组中年龄最大者的数据,请设计一个结构体,信息包括名字,年龄。输入5个人信息,然后再输出年龄最大的人的信息。
格式
输入格式: 输入名字性别为字符型,年龄整型
.
输出格式: 输出名字性别为字符型,年龄整型
样例1
输入格式:
Mike 25
Molly 37
Tom 16
Tony 15
Nana 59
.
输出格式: Nana 59
备注:
各人年龄唯一,且均为正数。
(2)参考代码
#include<stdio.h>
struct AgeMan{
char name[50];
int age;
};
struct AgeMan Minage[10];
int main()
{
int n,j,i;
for(n=1;n<=5;n++) scanf("%s %d",&Minage[n].name,&Minage[n].age);
for(i=0; i<5; i++){
for(j=0; j<5-i; j++){
if(Minage[j+1].age>Minage[j].age){
Minage[0] = Minage[j+1];
Minage[j+1] = Minage[j];
Minage[j] = Minage[0];
}
}
}
printf("%s %d",Minage[0].name,Minage[0].age);
return 0;
}
16. MT1566 幼者
(1)题目描述
输出结构体数组中年龄最小者的数据,请设计一个结构体,信息包括名字,年龄。输入5个人信息,然后再输出年龄最小的人的信息。
格式
输入格式: 输入名字性别为字符型,年龄整型
.
输出格式: 输出名字性别为字符型,年龄整型
样例1
输入格式:
Mike 25
Molly 37
Tom 16
Tony 15
Nana 59
.
输出格式: Tony 15
备注:
各人年龄唯一,且均为正数。
(2)参考代码
#include<stdio.h>
struct AgeMan{
char name[50];
int age;
};
struct AgeMan Minage[10];
int main()
{
int n,j,i;
for(n=1;n<=5;n++) scanf("%s %d",&Minage[n].name,&Minage[n].age);
for(i=0; i<5; i++){
for(j=0; j<5-i; j++){
if(Minage[j+1].age<Minage[j].age){
Minage[0] = Minage[j+1];
Minage[j+1] = Minage[j];
Minage[j] = Minage[0];
}
}
}
printf("%s %d",Minage[0].name,Minage[0].age);
return 0;
}
17. MT1567 员工薪水
(1)题目描述
有3个员工,从键盘输入数据,包括工号、姓名、薪水,工号薪水整型,姓名字符型,输出薪水最高的员工信息。不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一个员工的数据,空格分隔。
.
输出格式: 输出薪水最高的员工信息
样例1
输入格式:
101 mike 6688
102 miya 6516
103 tony 16648
.
输出格式: 103 tony 16648
备注:
各员工薪水唯一,且均为正数。
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct yuangong{
int id,salary;
string name;
}y[4];
int main( )
{
for(int i=0;i<3;i++){
cin>>y[i].id>>y[i].name>>y[i].salary;
}
int index=0,maxx=y[0].salary;
for(int i=1;i<3;i++){
if(maxx<y[i].salary){
maxx = y[i].salary;
index = i;
}
}
cout<<y[index].id<<" "<<y[index].name<<" "<<maxx<<endl;
return 0;
}
18. MT1568 学生成绩
(1)题目描述
有3个学生,每个学生有3门课的成绩,从键盘输入数据,包括学号、姓名、三门课成绩,学号整型,姓名字符型,成绩实型,计算3门课程总平均成绩,以及平均分最高的学生信息。不考虑非法成绩等特殊情况。
格式
输入格式: 每行输入一个学生的数据,空格分隔。
.
输出格式: 输出平均分最高的学生信息
样例1
输入格式:
101 mike 45 66 88
102 miya 65 16 18
103 tony 65 66 48
.
输出格式: 101 mike 45 66 88
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct student{
int id;
double source1,source2,source3;
string name;
}s[1005];
int main( )
{
double sum[105];
for(int i=0;i<3;i++){
cin>>s[i].id>>s[i].name>>s[i].source1>>s[i].source2>>s[i].source3;
sum[i]=s[i].source1+s[i].source2+s[i].source3;
}
int index=0;
double maxx=sum[0];
for(int i=1;i<3;i++){
if(maxx<sum[i]){
maxx = sum[i];
index = i;
}
}
cout<<s[index].id<<" "<<s[index].name<<" "<<s[index].source1<<" "<<s[index].source2<<" "<<s[index].source3;
return 0;
}
19. MT1569 小码哥学编程
(1)题目描述
小码哥买了3本编程书,他想先学习C语音,请帮他把C相关的书挑出来。请设计一个结构体,管理书籍的信息,信息包括种类,书名(不含空格),价格。输入书籍的信息,然后再输出所有的C相关的书信息。
格式
输入格式: 按行输入种类,书名为字符型,价格整型
.
输出格式: 按行输出种类,书名为字符型,价格整型
样例1
输入格式:
c cprimer 50
java hijava 30
c cbeginner 23
.
输出格式:
c cprimer 50
c cbeginner 23
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct book{
string name,kind;
int price;
}b[1005];
int main( )
{
for(int i=0;i<3;i++) cin>>b[i].kind>>b[i].name>>b[i].price;
for(int i=0;i<3;i++){
if(b[i].kind=="c"){
cout<<b[i].kind<<" "<<b[i].name<<" "<<b[i].price<<endl;
}
}
return 0;
}
20. MT1570 感冒来袭
(1)题目描述
冬天到了,社区居民被流感侵袭,校医院组织大家打疫苗,一共应该打3针才结束。社区有3个居民,从键盘输入数据,包括姓名、年龄、疫苗打了几针,年龄、疫苗整型,姓名字符型,输出所有还没打够针的人信息。不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一个学生的数据,空格分隔。
.
输出格式: 输出所有还没打够针的人信息
样例1
输入格式:
mike 45 3
miya 15 1
tony 65 2
.
输出格式:
miya 15 1
tony 65 2
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct cun{
string name;
int num,age;
}c[1005];
int main( )
{
for(int i=0;i<3;i++) cin>>c[i].name>>c[i].age>>c[i].num;
for(int i=0;i<3;i++){
if(c[i].num<3){
cout<<c[i].name<<" "<<c[i].age<<" "<<c[i].num<<endl;
}
}
return 0;
}
21. MT1571 贫困补助
(1)题目描述
有3个贫困学生,按家庭年收入发放贫困补助,从键盘输入数据,包括学号、姓名、家庭年收入,学号年收入整型,姓名字符型,年收入低于1万的发5000,低于2万的发3000,低于3万发1000,其他不发。
输出所有人信息及补助。
不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔。
.
输出格式: 输出所有信息
样例1
输入格式:
101 mike 4566
102 miya 15161
103 tony 65664
.
输出格式:
101 mike 4566 5000
102 miya 15161 3000
103 tony 65664 0
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct STUDENT{
int number;
char name[20];
int income;
};
int main( )
{
STUDENT stu;
int subsidy;
for(int j=0;j<3;j++){
scanf("%d %s %d",&(stu.number),stu.name,&(stu.income));
if(stu.income<10000) subsidy=5000;
else if(stu.income<20000) subsidy=3000;
else if(stu.income<30000) subsidy=1000;
else subsidy=0;
printf("%d %s %d %d\n",stu.number,stu.name,stu.income,subsidy);
}
return 0;
}
22. MT1572 交网费
(1)题目描述
小码哥又喜欢看电视又喜欢打电话聊天,每个月都要花掉很多网费。从键盘输入数据,包括第几季度、该季度网费、话费,其全部整型,计算小码哥今年花了多少钱。不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔。
.
输出格式: 输出整型
样例1
输入格式:
1 145 668
2 100 651
3 65 664
4 250 800
.
输出格式: 3343
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Cost{
int quarter;
int netFee;
int telFee;
}cost[4];
int main( )
{
int ans=0;
for(int i=0;i<4;i++){
cin>>cost[i].quarter>>cost[i].netFee>>cost[i].telFee;
}
for(int i=0;i<4;i++){
ans+=cost[i].netFee;
ans+=cost[i].telFee;
}
cout<<ans<<endl;
return 0;
}
23. MT1573 囤白菜
(1)题目描述
疫情期间,社区居民纷纷前往超市囤积食品,小码哥买了白菜、萝卜和豆腐,从键盘输入数据,包括菜名、重量(斤)、单价(元),其中重量、单价实型,菜名字符型,计算小码哥囤菜一共花了多少钱。不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔。
.
输出格式: 输出实型
样例1
输入格式:
baicai 10 3
luobo 15 1
doufu 5 4
.
输出格式: 65.000000
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Vegetable{
char foodName[1005];
double wight,danjia;
}Vegetable[3];
int main( )
{
double res;
for(int i=0;i<3;i++){
cin>>Vegetable[i].foodName>>Vegetable[i].wight>>Vegetable[i].danjia;
}
for(int i=0;i<3;i++){
res+=Vegetable[i].wight \* Vegetable[i].danjia;
}
cout<<fixed<<setprecision(6)<<res<<endl;
return 0;
}
24. MT1574 花友
(1)题目描述
小码哥是个花友,整天沉迷于网上购买花卉,每个月都要花掉很多费用,今年又买了4种花,从键盘输入数据,包括花名、数量、单价,其中花名字符型,其他其全部整型,计算小码哥今年花了多少钱。不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔。
.
输出格式: 输出平均分最高的学生信息
样例1
输入格式:
dujuan 115 30
shancha 50 5
yueji 65 20
zhizi 25 8
.
输出格式: 5200
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct huarui{
char name[1005];
int num,price;
}huarui[4];
int main( )
{
int ans=0;
for(int i=0;i<4;i++){
cin>>huarui[i].name>>huarui[i].num>>huarui[i].price;
}
for(int i=0;i<4;i++){
ans+=huarui[i].num\*huarui[i].price;
}
cout<<ans<<endl;
return 0;
}
25. MT1575 遛狗
(1)题目描述
小码哥减肥很多年了,屡战屡败,依然贼心不死,天天计算食物的卡路里。今天他又没管住嘴,大吃了一顿,只好吃完出门遛狗。从键盘输入数据,包括3种食物名、卡路里,其中食物名字符型,卡路里整型。
假定小区遛狗1圈消耗50卡路里,计算小码哥今天需要遛狗多少圈。
不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔。
.
输出格式: 输出实型
样例1
输入格式:
baicai 115
doufu 505
yangrou 6520
.
输出格式: 142.800000
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Food{
char name[1005];
int calorie;
}food[3];
int main( )
{
double ans;
for(int i=0;i<3;i++){
cin>>food[i].name>>food[i].calorie;
}
for(int i=0;i<3;i++){
ans+=food[i].calorie;
}
double res = ans\*1.0/50;
cout<<fixed<<setprecision(6)<<res<<endl;
return 0;
}
26. MT1576 减肥大计
(1)题目描述
小码哥酷爱减肥,他减肥的另一种方式是散步。目测他腹部,臀部,手臂,大腿脂肪比较多,从键盘输入这四种部位和脂肪含量,其中身体部位字符型,脂肪含量整型。
假定散步1天减掉0.05公斤脂肪,计算小码哥需要散步多少天。
不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔,如样例所示。
.
输出格式: 输出实型
样例1
输入格式:
fubu 45
tunbu 35
shou 10
tui 23
.
输出格式: 2260.000000
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct body{
char name[50];
int cal;
}body[4];
int main( )
{
int ans;
for(int i=0;i<4;i++){
cin>>body[i].name>>body[i].cal;
}
for(int i=0;i<4;i++){
ans+=body[i].cal;
}
double res = ans\*1.0/0.05;
cout<<fixed<<setprecision(6)<<res<<endl;
return 0;
}
27. MT1577 赡养老人
(1)题目描述
小码哥的爷爷奶奶年纪大了,小码哥的父母每个季度初都会给爷爷奶奶家用。′小码哥的爷爷奶奶每个月会从手里剩下的钱里花掉3000元(如果钱不够3000,则将手里的钱花完再想别的办法)。年底如果盈余就会把盈余包成红包送给小码哥当作压岁钱,没有盈余就没有红包压岁钱。
从键盘输入数据,包括第几个季度、汇款,都是整型。计算今年小码哥的压岁钱有多少钱。
不考虑非法输入等特殊情况。
格式
输入格式: 每行输入一组数据,空格分隔。
.
输出格式: 输出整型
样例1
输入格式:
1 14115
2 15015
3 16520
4 18888
.
输出格式: 28538
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Money{
int quarter;
int pay;
}money[3];
int main( )
{
for(int i=0;i<4;i++) cin>>money[i].quarter>>money[i].pay;
int temp=0;
for(int i=0;i<4;i++){
temp+=money[i].pay-3000\*3;
if(temp<0) temp=0;
}
cout<<temp<<endl;
return 0;
}
28. MT1578 复数
(1)题目描述
用下面的结构体类型表示复数:
struct COMPLEX { double r, i;};其中实部r、虚部i。
编写四个函数分别实现复数的和、差、积、商计算,在主函数中输入数据并调用这些函数得到复数运算结果。
格式
输入格式: 输入四个实数((可能有小数),空格分隔。
.
输出格式: 输出见样例。
样例1
输入格式: -1 -2 -3 -4
.
输出格式:
-4.000-6.000i
2.000+2.000i
-5.000+10.000i
0.440+0.080i
备注:
输出实型保留三位小数。
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct COMPLEX{
double r,i;
COMPLEX operator+(const COMPLEX &a){
COMPLEX rtn;
rtn.r = this->r+a.r;
rtn.i = this->i+a.i;
return rtn;
}
COMPLEX operator-(const COMPLEX &a){
COMPLEX rtn;
rtn.r = this->r-a.r;
rtn.i = this->i-a.i;
return rtn;
}
COMPLEX operator\*(const COMPLEX &a){
COMPLEX rtn;
rtn.r = this->r\*a.r-this->i\*a.i;
rtn.i = this->r\*a.i+ this->i\*a.r;
return rtn;
}
COMPLEX operator/(const COMPLEX &a){
COMPLEX rtn;
rtn.r = (this->r\*a.r+this->i\*a.i)/(a.r\*a.r+a.i\*a.i);
rtn.i = (this->i\*a.r-this->r\*a.i)/(a.r\*a.r+a.i\*a.i);
return rtn;
}
};
int main( )
{
COMPLEX a,b,c;
scanf("%lf %lf %lf %lf",&a.r,&a.i,&b.r,&b.i);
c = a+b;
if(c.i>0) printf("%.3lf+%.3lfi\n",c.r,c.i);
else if(c.i<0) printf("%.3lf%.3lfi\n",c.r,c.i);
c = a-b;
if(c.i>0) printf("%.3lf+%.3lfi\n",c.r,c.i);
else if(c.i<0) printf("%.3lf%.3lfi\n",c.r,c.i);
c = a\*b;
if(c.i>0) printf("%.3lf+%.3lfi\n",c.r,c.i);
else if(c.i<0) printf("%.3lf%.3lfi\n",c.r,c.i);
c = a/b;
if(c.i>0) printf("%.3lf+%.3lfi\n",c.r,c.i);
else if(c.i<0) printf("%.3lf%.3lfi\n",c.r,c.i);
return 0;
}
29. MT1579 线段与线段的关系
(1)题目描述
设计分数类型:
struct FRACTION { int fenzi, fenmu;};
fenzi是分子fenmu是分母,编写四个函数分别实现分数的和、差、积、商计算,在主函数中输入4个正整数,分别表示两个分数的分子分母,然后调用这些函数得到分数运算结果。
格式
输入格式: 输入4个正整数,空格分隔。
.
输出格式: 输出4行,分别代表和、差、积、商。注意输出格式。
样例1
输入格式: 1 2 3 4
.
输出格式:
5/4
-1/4
3/8
2/3
备注:
1、要求输出最简分数。
2、若为负数,负号写开头位置。
3、若分母为1,则不输出分母。
4、不会出现分母为0的特殊情况。
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Fraction{
int fenzi,fenmu;
}fraction[2];
int gcd(int x,int y){
return (!y)?x:gcd(y,x%y);
}
void myPrint(int zi,int mu){
bool isPositive = true;
if((zi\*mu)<0) isPositive = false;
zi = abs(zi);
mu = abs(mu);
if(mu==1){
if(isPositive) printf("%d\n",zi);
else printf("-%d\n",zi);
}else{
if(isPositive) printf("%d/%d\n",zi,mu);
else printf("-%d/%d\n",zi,mu);
}
}
int main( )
{
int zi=0,mu=0;
for(int i=0;i<2;i++){
cin>>fraction[i].fenzi>>fraction[i].fenmu;
}
// 加
zi = fraction[0].fenzi\*fraction[1].fenmu+fraction[1].fenzi\*fraction[0].fenmu;
mu = fraction[0].fenmu\*fraction[1].fenmu;
int temp = gcd(zi,mu);
zi /= temp;
mu /= temp;
myPrint(zi, mu);
//减
zi = fraction[0].fenzi\*fraction[1].fenmu-fraction[1].fenzi\*fraction[0].fenmu;
mu = fraction[0].fenmu\*fraction[1].fenmu;
temp = gcd(zi,mu);
zi /= temp;
mu /= temp;
myPrint(zi, mu);
//乘
zi = fraction[0].fenzi\*fraction[1].fenzi;
mu = fraction[0].fenmu\*fraction[1].fenmu;
temp = gcd(zi,mu);
zi /= temp;
mu /= temp;
myPrint(zi, mu);
//除
zi = fraction[0].fenzi\*fraction[1].fenmu;
mu = fraction[0].fenmu\*fraction[1].fenzi;
temp = gcd(zi,mu);
zi /= temp;
mu /= temp;
myPrint(zi, mu);
return 0;
}
30. MT1580 补考
(1)题目描述
设有一个学校人员信息表,其中学生信息包括姓名、号码、性别、班级和成绩,成绩整型,其他字符型,输入人员数据,统计学生不及格的人数。
格式
输入格式: 第一行输入人数,随后每行一个学生的信息,共n位学生。
.
输出格式: 输出整型
样例1
输入格式:
5
zhang 2020001 F 101 98
li 2020002 F 101 28
wang 2020003 M 102 18
deng 2020009 M 103 44
cao 2020011 F 104 91
.
输出格式: 3
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Student{
char name[20];
char tel[15];
char sex[5];
char classID[20];
int grade;
}stduent[1005];
int main( )
{
int n,cnt=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>stduent[i].name>>stduent[i].tel>>stduent[i].sex>>stduent[i].classID>>stduent[i].grade;
}
for(int i=0;i<n;i++){
if(stduent[i].grade<60) cnt++;
}
cout<<cnt<<endl;
return 0;
}
31. MT1581 讲师
(1)题目描述
设有一个学校人员信息表,其中教师信息包括姓名、号码、性别、职称和工资,工资整型,其他字符型,输入人员数据,统计职称为讲师的人数。
格式
输入格式: 第一行输入教师人数n,随后每行一个教师的信息,共n位教师。
.
输出格式: 输出整型
样例1
输入格式:
5
zhang 101 F jiaoshou 98
li 102 F jiangshi 28
wang 103 M jiangshi 18
deng 109 M jiangshi 44
cao 111 F jiaoshou 91
.
输出格式: 3
(2)参考代码
import java.util.Scanner;
import java.util.\*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count=0;
for(int i=0;i<n;i++){
String name = sc.next();
String tel = sc.next();
String sex = sc.next();
String level = sc.next().toLowerCase();
int salary = sc.nextInt();
if(level.contains("jiangshi")) count++;
}
System.out.println(count);
sc.close();
}
}
32. MT1582 星期几
(1)题目描述
设计日期类型如下: struct DATE { int month, day;};
已知1月1日是星期五(假设该年是非闰年),计算输入的日期为星期几。用整数1、2、3等等分别代表周一、周二、周三等等。
格式
输入格式: 输入月、日,整型,空格分隔
.
输出格式: 输出整型
样例1
输入格式: 12 25
.
输出格式: 6
备注:
周日用7表示。
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct DATE{
int month,day;
};
int main( )
{DATE date;
int tempday,MOD;
cin >> date.month >> date.day;
int a[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
tempday=a[date.month-1]+date.day+5;
MOD = tempday%7;
MOD = MOD+6;
if(MOD>7) MOD = MOD%7;
printf("%d",MOD);
return 0;
}
33. MT1583 日期
(1)题目描述
设计日期类型如下: struct DATE { int month, day;};
假设某一年是非闰年。编写函数计算输入的日期加减n天(正为后,负为前)的日期。不考虑超出该年的情况。
格式
输入格式: 第一行月、日,空格分隔,第二行输入n,整型。
.
输出格式: 输出年月日,空格分隔,整型
样例1
输入格式:
12 21
4
.
输出格式: 12 25
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct DATE{
int month,day;
};
int DATEtoDAY(DATE date){
int count=0;
int m[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=1;i<=date.month;i++)
count += m[i-1];
count += date.day;
return count;
}
DATE DAYtoDATE(int count){
DATE date;
int m[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i=1;
while(count>m[i]){
count -= m[i];
i++;
}
date.month = i;
date.day = count;
return date;
}
int main( )
{
DATE date;
scanf("%d %d",&date.month,&date.day);
int n;
scanf("%d",&n);
int count=DATEtoDAY(date);
count += n;
date = DAYtoDATE(count);
printf("%d %d",date.month,date.day);
return 0;
}
34. MT1584 日期差
(1)题目描述
设计日期类型如下: struct DATE { int month, day;};
假设某一年是非闰年。输入该年内的两组日期,计算两个日期间的差((天数)。统一用后输入的日期减去先输入的日期。
格式
输入格式: 分两行输入两组月、日,空格分隔。
.
输出格式: 输出整型
样例1
输入格式:
12 21
12 19
.
输出格式: -2
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct DATE{
int month,day;
};
int DATEtoDAY(DATE date){
int count=0;
int m[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=1;i<=date.month;i++)
count += m[i-1];
count += date.day;
return count;
}
DATE DAYtoDATE(int count){
DATE date;
int m[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i=1;
while(count>m[i]){
count -= m[i];
i++;
}
date.month = i;
date.day = count;
return date;
}
int main( )
{
DATE date1,date2;
scanf("%d %d",&date1.month,&date1.day);
scanf("%d %d",&date2.month,&date2.day);
int n=DATEtoDAY(date2)-DATEtoDAY(date1);
printf("%d",n);
return 0;
}
35. MT1585 两点距离
(1)题目描述
用下面的数据类型分别表示点: struct POINT { int x, y; };
输入两个点的坐标值x和y,编写函数求两点距离。
格式
输入格式: 输入整型,空格分隔。每行一个点的坐标。
.
输出格式: 输出实型(两位小数)
样例1
输入格式:
-20 20
20 -10
.
输出格式: 50.00
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Point{
int x,y;
}point[2];
int main( )
{
for(int i=0;i<2;i++){
cin>>point[i].x>>point[i].y;
}
double dist=0;
dist = sqrt(pow(point[0].x-point[1].x,2.0)+pow(point[0].y-point[1].y,2.0));
cout<<fixed<<setprecision(2)<<dist<<endl;
return 0;
}
36. MT1586 矩形面积
(1)题目描述
用下面的数据类型分别表示点和矩形:struct POINT{//点
int x, y;//坐标值x和y
};
struct RECT{//矩形
POINT It, rb;//矩形的左上角和右下角
};
有一个矩形,矩形的边分别和x,y轴平行,输入矩形两个点的坐标值x和y,编写函数求矩形面积。不考虑溢出之类的特殊情况。
格式
输入格式: 输入整型,空格分隔。每行一个点的坐标。
.
输出格式: 输出整型
样例1
输入格式:
-20 20
20 -10
.
输出格式: 1200
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Point{
int x,y;
}point[2];
struct Rect{
Point lt,rb;
}rect;
int main( )
{
int ans;
for(int i=0;i<2;i++){
cin>>point[i].x>>point[i].y;
}
rect.lt = point[0],rect.rb = point[1];
int length =0,width=0;
length = abs(rect.lt.x-rect.rb.x);
width = abs(rect.lt.y-rect.rb.y);
ans=length\*width;
cout<<ans<<endl;
return 0;
}
37. MT1587 圆面积
(1)题目描述
用下面的数据类型分别表示点和圆:
struct POINT {//点
int x, y;//坐标值x和y
};
struct CIRCLE{//圆
POINT C;//圆心
double r;//半径
};
依次输入圆心的坐标值x、y和半径,编写函数求圆面积。
格式
输入格式: 输入整型,空格分隔。
.
输出格式: 输出实型,保留2位小数。
样例1
输入格式: -20 20 50
.
输出格式: 7853.98
备注:
PI取3.1415926
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
double res,PI=3.1415926;
struct Point{
int x,y;
}point;
struct Rect{
Point c;
double r;
}rect;
int main( )
{
cin >> point.x >> point.y >>rect.r;
rect.c = point;
res = PI\*rect.r\*rect.r;
cout<<fixed<<setprecision(2)<<res<<endl;
return 0;
}
38. MT1588 最大的长方体
(1)题目描述
输入n (n<10000)个长方体的长l,宽w,高h,求其表面积最大的立方体。
格式
输入格式: 第一行一个整数n , (0<n<10000)代表长方体个数。接下来包含n行,第行表示一个长方体,包含空格分开的3个整数,代表长.宽、高
.
输出格式: 一个数字,代表最大的立方体的编号
样例1
输入格式:
3
1 2 3
2 3 4
3 4 5
.
输出格式: 3
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Cuboid{
int l,w,h;
}cuboid[1005];
int main( )
{
ll n;
int index=0,maxx=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>cuboid[i].l>>cuboid[i].w>>cuboid[i].h;
}
for(int i=1;i<=n;i++){
ll temp=0;
temp=(cuboid[i].l\*cuboid[i].w+cuboid[i].l\*cuboid[i].h+cuboid[i].h\*cuboid[i].w)\*2;
if(temp>maxx){
maxx = temp;
index = i;
}
}
cout<<index<<endl;
return 0;
}
39. MT1589 园的边框
(1)题目描述
用下面的数据类型分别表示点和圆:
struct POINT {//点
int x, y;//坐标值x和y
};
struct CIRCLE {//圆
POINT C;//圆心
double r;//半径
};
依次输入圆心的坐标值x、 y和半径,再在第二行输入第2个点的坐标,判断第2个点是否在圆的边框上。
格式
输入格式: 输入整型,空格分隔。
.
输出格式: 输出YES或者NO
样例1
输入格式:
-20 20 50
0 0
.
输出格式: NO
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Point{
int x,y;
}point[2];
struct Rect{
Point c;
double r;
}rect;
int main( )
{
cin>>point[0].x>>point[0].y>>rect.r;
cin>>point[1].x>>point[1].y;
rect.c = point[0];
double dist=0;
dist = sqrt(pow(point[0].x-point[1].x,2.0)+pow(point[0].y-point[1].y,2.0));
if(abs(dist-rect.r)<0.000001) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
40. MT1590 矩形的边框
(1)题目描述
用下面的数据类型分别表示点和矩形:
struct POINT{//点
int x, y;//坐标值x和y
};
struct RECT {//矩形
POINT It, rb;//矩形的左上角和右下角
};
输入矩形两个点的坐标值x和y,再输入第3个点的坐标,判断第3个点是否在矩形的边框上。
格式
输入格式:
第一行输入左上角坐标
第二行输入右下角坐标
第三行输入第三个点的坐标输入整型,空格分隔。
.
输出格式: 输出YES或者NO
样例1
输入格式:
-20 20
20 -10
20 10
.
输出格式: YES
备注:
矩形平行于x、y轴
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Point{
int x,y;
}point[5];
struct Rect{
Point lt,rb;
}rect;
int main( )
{
bool flag=false;
for(int i=1;i<=3;i++) cin>>point[i].x>>point[i].y;
rect.lt = point[1];
rect.rb = point[2];
if(point[3].x==rect.lt.x || point[3].x == rect.rb.x){
if(point[3].y >= rect.rb.y && point[3].y <=rect.lt.y)
flag=true;
}
if(point[3].y == rect.lt.y || point[3].y == rect.rb.y){
if(point[3].x >= rect.lt.x && point[3].x <= rect.rb.x)
flag=true;
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
41. MT1591 圆的内部
(1)题目描述
用下面的数据类型分别表示点和圆:
struct POINT{//点
int x, y;l/坐标值x和y
};
struct CIRCLE{//圆
POINT c;//圆心
double r;l/半径
};
输入圆心的坐标值xy和半径,再在第二行输入第2个点的坐标,判断第2个点是否在圆的内部上。
格式
输入格式: 输入整型,空格分隔。
.
输出格式: 输出YES或者NO
样例1
输入格式:
-20 20 50
0 0
.
输出格式: YES
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct Point{
int x,y;
}point[2];
struct Rect{
Point c;
double r;
}rect;
int main( )
{
cin>>point[0].x>>point[0].y>>rect.r;
cin>>point[1].x>>point[1].y;
rect.c = point[0];
double dist=0;
dist = sqrt(pow(point[0].x-point[1].x,2.0)+pow(point[0].y-point[1].y,2.0));
if(rect.r-dist>0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
42. MT1592 矩形的内部
(1)题目描述
用下面的数据类型分别表示点和矩形:
struct POINT {//点
int x, y;//坐标值x和y
};
struct RECT{//矩形
POINT It, rb;//矩形的左上角和右下角
};
输入矩形两个点的坐标值x和y,再输入第3个点的坐标,判断第3个点是否在矩形的内部((不含边框)。
格式
输入格式: 输入整型,空格分隔。每行一个点的坐标。
.
输出格式: 输出YES或者NO
样例1
输入格式:
-20 20
20 -10
-20 -10
.
输出格式: NO
备注:
矩形平行于x、y轴
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct POINT{
int x,y;
};
struct RECT{
POINT lt,rb;
};
int main(){
RECT rect;
POINT point;
scanf("%d %d", &(rect.lt.x), &(rect.lt.y));
scanf("%d %d", &(rect.rb.x), &(rect.rb.y));
scanf("%d %d", &(point.x), &(point.y));
if((point.x > rect.lt.x && point.x<rect.rb.x)&&(point.y > rect.rb.y && point.y < rect.lt.y))
printf("YES\n");
else printf("NO\n");
return 0;
}
43. MT1593 点到线
(1)题目描述
用下面的数据类型分别表示点和线:
struct POINT{//点
int x, y;//坐标值x和y
};
struct LINE{//线
POINT s, e;//线的两端
};
输入线段两个端点的坐标值x和y,再输入第3个点的坐标,计算第3个点距这条线的最近距离。
格式
输入格式: 输入整型,空格分隔。每行一个点的坐标。
.
输出格式: 输出实型,保留两位小数
样例1
输入格式:
-20 20
20 -10
0 0
.
输出格式: 4.00
备注:
此题求的是点到直线最短距离
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct POINT{ //点
int x,y; //坐标值×和y
};
struct LINE{ //线
POINT s,e; //线的两端
};
int main()
{
POINT p;
LINE line;
double s,d,h;
scanf("%d%d", &line.s.x, &line.s.y);
scanf("%d%d", &line.e.x, &line.e.y);
scanf("%d%d", &p.x, &p.y);
s=fabs(line.s.x\*(line.e.y-p.y)+line.e.x\*(p.y-line.s.y)+p.x\*(line.s.y-line.e.y))/2;
d=sqrt((line.e.x-line.s.x)\*(line.e.x-line.s.x)+(line.e.y-line.s.y)\*(line.e.y-line.s.y));
h=s\*2/d;
printf("%.2lf\n",h);
return 0;
}
44. MT1594 点到圆
(1)题目描述
用下面的数据类型分别表示点和圆:
struct POINT{//点
int x, y;//坐标值x和y
};
struct CIRCLE{//圆
POINT c;//圆心
double r;//半径
};
依次输入圆心的坐标值x、y和半径,再在第二行输入第2个点的坐标,计算第2个点距这个圆的最近距离。如果点在圆内部或者边框上,距离计为0。
格式
输入格式: 第一行输入圆心坐标和半径,第二行输入第二个点。空格分离。其中除半径为实型外,其他均为整型。
.
输出格式: 输出实型距离(保留两位小数)。如果在圆内部或边框上,输出0。
样例1
输入格式:
-20 20 50
0 0
.
输出格式: 0
样例2
输入格式:
1 2 4.5
4 7
.
输出格式: 1.33
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
double res;
struct Point{
int x,y;
}point[2];
struct Circle{
Point c;
double r;
}circle;
int main( )
{
cin>>point[0].x>>point[0].y>>circle.r;
cin>>point[1].x>>point[1].y;
circle.c = point[0];
double dist = 0;
dist = sqrt(pow(point[1].x - circle.c.x,2.0)+pow(point[1].y-circle.c.y,2.0));
if(dist - circle.r<=0) cout<<0<<endl;
else{
res = dist-circle.r;
cout<<fixed<<setprecision(2)<<res<<endl;
}
return 0;
}
45. MT1595 点到矩形
(1)题目描述
用下面的数据类型分别表示点和矩形:
struct POINT {//点
int x, y;/I坐标值x和y
};
struct RECT{//矩形
POINT lt, rb;//矩形的左上角和右下角
};
输入矩形两个点的坐标值x和y,再输入第3个点的坐标,计算第3个点距这个矩形的最近距离。如果点在矩形内部或者边框上,距离计为0。
格式
输入格式: 输入整型,空格分隔。每行一个点的坐标。
.
输出格式: 输出实型。如果在矩形内部或边框上,输出0。
样例1
输入格式:
-20 20
20 -10
20 10
.
输出格式: 0
样例2
输入格式:
0 10
10 0
-1 -1
.
输出格式: 1.414214
备注:
矩形平行于x、y轴
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct POINT{ //点
int x,y; //坐标值×和y
};
struct LINE{ //线
POINT s,e; //线的两端
};
struct RECT{ //矩形
POINT lt,rb; //矩形的左上角和右下角
};
double pointToPoint(POINT a,POINT b){
double d =sqrt((a.x-b.x)\*(a.x-b.x)+(a.y-b.y)\*(a.y-b.y)); return d;
return d;
}
double pointToLine(POINT p,LINE l){
double s=fabs(l.s.x\*(l.e.y-p.y)+l.e.x\*(p.y-l.s.y)+p.x\*(l.s.y-l.e.y))/2;
double d=pointToPoint(l.s,l.e);
double h=s\*2/d;
return h;
}
int main()
{
POINT plt,plb,prt,prb,point;
LINE lineLeft,lineRight,lineTop,lineBottom;
RECT rect;
scanf("%d %d",&plt.x,&plt.y);
scanf("%d %d",&prb.x,&prb.y);
scanf("%d %d",&point.x,&point.y);
plb.x=plt.x,plb.y=prb.y;
prt.x=prb.x,prt.y=plt.y;
lineLeft.e=plb,lineLeft.s=plt;
lineRight.e=prb,lineRight.s=prt;
lineBottom.e=plb,lineBottom.s=prb;
lineTop.e=plt,lineTop.s=prt;
rect.lt=plt,rect.rb=prb;
if(plt.x<=point.x&point.x<=prt.x&plb.y<=point.y&&point.y<=plt.y)
printf("0");
else{
//矩形×范围内上方或下方
if(plt.x<=point.x&point.x<=prt.x){
double d1=pointToLine(point,lineTop);double d2=pointToLine(point,lineBottom);printf("%lf",min(d1,d2));
return 0;
}
//矩形y范围内左侧或右侧
if(plb.y<=point.y&&point.y<=plt.y){
double d1=pointToLine(point,lineLeft);
double d2=pointToLine(point,lineRight);
printf("%lf",min(d1,d2));
return 0;
}
//其他情况,取最近的顶点距离作为距离
double d1=pointToPoint(point,plt);
double d2=pointToPoint(point,plb);
double d3=pointToPoint(point,prt);
double d4=pointToPoint(point,prb);
printf("%lf",min(min(d1,d2),min(d3,d4)));
return 0;
}
}
46. MT1596 线到矩形
(1)题目描述
用下面的数据类型分别表示点、线和矩形:
struct POINT {//点n的阶乘
int x, y;l/坐标值x和y
};
struct LINE{//线P
OINT s, e;//线的两端
};
struct RECT {//矩形
POINT It, rb;//矩形的左上角和右下角
};
输入矩形两个点的坐标值,再输入线段的端点的坐标值,判断线段是否会与矩形面相交,输出YES或者NO。
线段与矩形面相交的定义:只要线段上有一点在矩形框上或者框内,则认为该线段与矩形面相交。
格式
输入格式: 第一行输入矩形两个点的坐标值,第二行输入线段的端点的坐标值,空格分隔。
.
输出格式: 输出YES或者NO
样例1
输入格式:
-20 20 20 -10
20 10 -20 -10
.
输出格式: YES
(2)参考代码
#include<bits/stdc++.h>
using namespace std;
struct POINT{
int x,y;
};
struct LINE{
POINT s,e;
};
struct RECT{
POINT lt,rb;
};
bool intersect(LINE AB,LINE CD){//判断线段CD是否与直线AB相交
//直线AB的直线方程为:
// f(x,y)=(y-A.y)\*(A.x-B.x)-(x-A.x)\*(A.y-B.y)=0
POINT A=AB.e,B=AB.s;
POINT C=CD.e,D=CD.s;
int fc=(C.y-A.y)\*(A.x-B.x)-(C.x-A.x)\*(A.y-B.y);
int fd=(D.y-A.y)\*(A.x-B.x)-(D.x-A.x)\*(A.y-B.y);
if(fc\*fd<=0) return true;
else return false;
}
//判断两线段是否相交
bool interSegment(LINE AB,LINE CD){
if(intersect(AB, CD) && intersect(CD, AB)) return true;
else return false;
}
bool inRect(POINT point,RECT rect){
if(point.x<=rect.rb.x&point.x>=rect.lt.x&&point.y<=rect.lt.y&&point.x>=rect.rb.y)return true;
else return false;
}
int main (){
int x1,y1,x2,y2,x3,y3,x4,y4; cin >>x1>>y1>>x2>>y2;
cin >>x3>>y3>>x4>>y4;
POINT LT {x1,y1}, LB {x1,y2}, RT {x2,y1}, RB {x2,y2}, lineA {x3,y3},lineB{x4,y4};
RECT rect { LT , RB };
LINE diag1{ LT , RB },diag2{ LB , RT }, lineAB { lineA , lineB };
bool flag = false ;
if ( inRect ( lineA , rect )|| inRect(lineB, rect ))
flag = true ;
if ( interSegment ( lineAB ,diag1) || interSegment ( lineAB ,diag2))
flag = true ;
if ( flag ) cout <<"YES ";
else cout <<"NO";
return 0;
}
47. MT1597 平行线
(1)题目描述
用下面的数据类型表示线:
struct POINT {//点
int x, y;/l坐标值x和y
};
struct LINE{//线
POINT s, e;//线的两端
};
输入2个线段的端点的坐标值x和y,判断两条线段所在直线是否为平行线。如果两线段共线,判为不平行。
格式
输入格式:输入整型,空格分隔。按照先起点(x,y)再终点(x,y)的次序。每行一个线段的信息。
.
输出格式: 输出YES或者NO
样例1
输入格式:
-20 20 20 -10
0 0 5 0
.
输出格式: NO
(2)参考代码
#include<bits/stdc++.h>
using namespace std;


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以戳这里获取](https://gitee.com/vip204888)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**