7月29日测试

今天第一次考试,题目是不难,但是还是有些细节不太注意,,;还有就是提交文件的步骤要精确;否则就零分了;。

1)分配任务

【问题描述】

   在社会实践活动中有三项任务分别是:种树、采茶、送水。依据小组人数及男生、女生人数决定小组的接受任务,人数小于10人的小组负责送水(输出water),人数大于等于10人且男生多于女生的小组负责种树(输出tree),人数大于等于10人且男生不多于女生的小组负责采茶(输出tea)。输入小组男生人数、女生人数,输出小组接受的任务。

【输入】一行两个空格隔开的数,表示小组中男生和女生的人数。

【输出】输出对应的任务。

zz
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<iomanip>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     freopen("task.in","r",stdin);
 9     freopen("task.in","r",stdin);
10     int a,b,c;
11     cin>>a>>b;
12     c=a+b;
13     if(c<10)
14         cout<<"water"<<endl;
15     if(c>=10)
16     {
17         if(a>b)
18             cout<<"tree"<<endl;
19         if(a<=b)
20             cout<<"tea"<<endl;
21     }
22     return 0;
23 }
 
 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     freopen("task.in","r",stdin);
 7     freopen("task.out","w",stdout);
 8     int a,b;
 9     cin>>a>>b;
10     if(a+b<10)
11         cout<<"water"<<endl;
12     if(a+b>=10&&a>b)
13         cout<<"tree"<<endl;
14     if(a+b>=10&&a<=b)
15         cout<<"tea"<<endl;
16     return 0;
17 }
View Code

这个if语句有些不清晰但还好吧  //。

计算距离  

【问题描述】

   在平面中之角坐标系中,两个点A(x1,y1),B(x2,y2)的距离有很多种衡量方式,其中有两种很常用。

第一种是直线距离:

第二种叫做曼哈顿距离,公式如下:

【输入】四个正整数x1,y1,x2,y2。

【输出】一共两行,每行一个数。第一行输出直线距离。第二行输出曼哈顿距离。要求:保留两位小数。

zz
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<iomanip>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     freopen("distance.in","r",stdin);
 9     freopen("distance.in","r",stdin);
10     int x1,y1,x2,y2;
11     double z,m;
12     cin>>x1>>y1>>x2>>y2;
13     z=sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
14     m=(x1-x2)+(y1-y2);
15     if(m<0)
16         m*=-1;
17     cout<<setiosflags(ios::fixed)<<setprecision(2);
18     cout<<z<<endl;
19     cout<<m<<endl;
20     return 0;
21 }

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iomanip>
 5 using namespace std;
 6 int main()
 7 {
 8     freopen("distance.in","r",stdin);
 9     freopen("distance.out","w",stdout);
10     cout<<setiosflags(ios::fixed)<<setprecision(2);
11     int xx1,xx2,yy1,yy2;
12     cin>>xx1>>yy1>>xx2>>yy2;
13     double c,d,e,f;
14     c=sqrt(1.0*(xx1-xx2)*(xx1-xx2)+1.0*(yy1-yy2)*(yy1-yy2));
15     if(xx1<xx2)
16         d=xx2-xx1;
17     else
18         d=xx1-xx2;
19     if(yy1<yy2)
20         e=yy2-yy1;
21     else
22         e=yy1-yy2;
23     f=d+e;
24     cout<<c<<endl<<f<<endl;
25     return 0;
26 }
View Code

还是不擅长熟练运用if,else,, 细节问题不周到,,

蜗牛

【问题描述】蒟蒻蜗牛lzh掉到了一口深井底部,但是他有梦想,他一定要爬出来!!已知井的深度D厘米,以及lzh每天白天能向上爬a厘米。但是最惨的在后面:lzh每天晚上睡觉的时候都会向下滑b厘米。现在是第一天早上,lzh开始向上爬,lzh想知道从今天算起,他第几天才能重见天日(爬出深井)。

【输入】一行三个空格隔开的正整数D,a,b。

【输出】如果lzh能爬上来,输出一个数,代表lzh第几天才能重见天日,如果lzh永远爬不上来,输出“bye bye”。

zz
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<iomanip>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     freopen("snail.in","r",stdin);
 9     freopen("snail.in","r",stdin);
10     int D,a,b,day;
11     cin>>D>>a>>b;
12     if(a<=b)
13         cout<<"bye bye"<<endl;
14     else
15     {
16         if(D%(a-b)==0)
17                 day=D/(a-b);
18         else
19                 day=D/(a-b)+1;
20         cout<<day<<endl;
21     }
22     return 0;
23 }

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     freopen("snail.in","r",stdin);
 7     freopen("snail.out","w",stdout);
 8     int D,a,b,x=0;//x是计数器
 9     cin>>D>>a>>b;
10     if(a<=b&&D>a)
11         cout<<"bye bye"<<endl;
12     else
13     {
14         for(;;)
15         {
16             x++;
17             D-=a;
18             if(D<=0)
19                 break;
20             D+=b;
21         }
22         cout<<x<<endl;
23     }
24     return 0;
25 }
View Code

这个题是真的,嗯,没有想到蜗牛第一天就能爬上井口,,还是考虑不周吧。也没有熟练掌握循环语句的使用,,

.鱼的排队

【问题描述】lxt有一项超能力,就是和焦作一中的湖里的鱼儿进行交流,lxt和其中的5条鱼成为了最好的朋友,他决定在某一天让这5条鱼排成一队,在湖里游行,排队的规则就是按照鱼的编号从小到大进行。 现在lxt知道了这5条鱼的编号,想知道这5条鱼的编号从小到大排序后的结果,希望你写个程序帮助他。对于写过3个数排序的你来说,5条鱼的排序当然不在话下。

【输入】一行,5个用空格隔开的整数。

【输出】一行,从小到大排序后的整数,每个整数用1个空格隔开

zz
 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     freopen("fivesort.in","r",stdin);
 7     freopen("fivesort.out","w",stdout);
 8     int a,b,c,d,e,minn;
 9     cin>>a>>b>>c>>d>>e;
10     for(int i=1;i<=5;i++)
11     {
12         minn=1000000;
13         if(a<minn)
14             minn=a;
15         if(b<minn)
16             minn=b;
17         if(c<minn)
18             minn=c;
19         if(d<minn)
20             minn=d;
21         if(e<minn)
22             minn=e;
23         if(a==minn)
24             a=10000000;
25         else 
26         {
27             if(b==minn)
28                 b=1000000;
29             else
30             {
31                 if(c==minn)
32                     c=10000000;
33                 else
34                 {
35                     if(d==minn)
36                         d=10000000;
37                     else
38                         e=10000000;
39                 }
40             }
41         }
42         cout<<minn<<' ';
43     }
44     return 0;
45 }
View Code

这个是方法有些笨了,,答案上给的是循环,方法很好,,所以遇到这种情况就要用循环了。。

 

转载于:https://www.cnblogs.com/zoutong2020/p/7257469.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值