20 条题解

  • 84
    @ 2022-8-12 21:53:03

    这题的 LV 10 写的有点乱,而且这还是蓝桥杯的题!这么简单吗?搞得我心烦意乱,我先讲讲我的思路吧!

    1. 输入 a 和 b 因为要有一个是实数,所以 up 懒得写两行,就直接全部用 double 了
    2. 然后用三个判断语句
    3. ①:a < 40 输出 a * b
    4. ②:a >= 40 && a <= 50 输出 40 * b + (a - 40) * b * 1.5
    5. ③:else 输出 40 * b + 10 * b * 1.5 + (a - 50) * b
    6. 保留两位小数就不用我讲了吧,前面讲过的就不讲了哈~

    上代码!求求了,点个赞吧大家(写题解不易!)

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        double a, b;
        cin >> a >> b;
        if (a < 40) printf("%.2lf", a * b);
        else if (a >= 40 && a <= 50) printf("%.2lf", 40 * b + (a - 40) * 1.5 * b);
        else printf("%.2lf", 40 * b + 10 * 1.5 * b + (a - 50) * 2 * b);
        return 0;
    }
    
    • 13
      @ 2023-8-17 12:52:32
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          double g, x, sum = 0;
          cin >> g >> x;
          if (g < 40)
          {
              sum += g * x;
          }
          if (g >= 40 && g < 50)
          {
              sum += 40 * x;
              sum += (g - 40) * (x * 1.5);
          }
          if (g >= 50)
          {
              sum += 40 * x;
              sum += 10 * x * 1.5;
              sum += (g - 50) * x * 2;
          }
          printf("%0.2lf", sum);
          return 0;
      }
      //制作不易,求点赞,谢谢!
      
      • 12
        @ 2023-8-3 20:13:01
        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            double a, b;
            cin >> a >> b;
            if (a < 40) printf("%.2lf", a * b);
            else if (a >= 40 && a <= 50) printf("%.2lf", 40 * b + (a - 40) * 1.5 * b);
            else printf("%.2lf", 40 * b + 10 * 1.5 * b + (a - 50) * 2 * b);
            return 0;
        }
        求点赞!!!
        (会看讨论,有问题找我)
        
        • 10
          @ 2022-8-21 10:48:31

          这道题其实就是要分段计算总薪水,用if-else if就能轻松搞定啦~


          1.ab设成double,毕竟double也能存储整数^o^

          2.进行分段计算:

          (1)如果时间<=40,那就按常规方法来,直接a*b

          (2)如果40<时间<=50,先算40小时的,再加上超额的

          (3)如果时间>50,还是先算40小时的,再加40~50的,最后加超过50的

          3.最后保留2位小数输出


          养成好习惯,看代码前点个赞(滑稽)

          #include<iostream>
          #include<cstdio>
          using namespace std;
          int main(){
          	double t,q,sum;
          	cin>>t>>q;
          	if(t<=40) sum=t*q;//常规方法计算 
          	else if(t<=50) sum=40*q+(t-40)*q*1.5;//常规+超额部分
          	else if(t>50) sum=40*q+10*q*1.5+(t-50)*q*2;//常规+40~50小时部分+超出50小时部分
          	printf("%.2f",sum);//保留2位小数输出 
          	return 0; 
          }
          
          • 4
            @ 2023-11-13 10:19:46

            已AC答案,请放心食用:

            #include <iostream>
            #include <iomanip>
            using namespace std;
            int main()
            {
                double x, y, sum = 0;
                cin >> x >> y;
                if (x <= 40)
                {
                    sum += x * y;
                }
                else if (x <= 50)
                {
                    sum += 40 * y;
                    sum += (x - 40) * y * 1.5;
                }
                else
                {
                    sum += 40 * y;
                    sum += 10 * (y * 1.5);
                    sum += (x - 50) * y * 2;
                }
                cout << fixed << setprecision(2) << sum << endl;
                return 0;
            }
            
            • @ 2024-3-23 17:55:51

              我都没Ac!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

          • 2
            @ 2024-2-5 12:15:13
            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                double a, b;
                cin >> a >> b;
                if (a < 40) printf("%.2lf", a * b);
                else if (a >= 40 && a <= 50) printf("%.2lf", 40 * b + (a - 40) * 1.5 * b);
                else printf("%.2lf", 40 * b + 10 * 1.5 * b + (a - 50) * 2 * b);
                return 0;
            }
            
            • 2
              @ 2023-11-21 20:50:16
              #include<bits/stdc++.h>
              using namespace std;
              int main(){
              	int n;
              	double m,a=0;
              	cin>>n>>m;
              	if(n<=40){
              		a=n*m;
              	}
              	else{
              		if(n<=50){
              			a=40*m;
              			n-=40;
              			a+=n*1.5*m;
              		}
              		else{
              			a=40*m;
              			n-=50;
              			a+=10*1.5*m;
              			a+=n*2*m;
              		}
              	}
              	printf("%.2lf",a);
              	return 0;
              }
              
              • 2
                @ 2023-8-15 13:19:43
                #include <bits/stdc++.h>
                #include<cstdio>
                using namespace std;
                int main()
                {
                    double n,m; 
                    cin>>n>>m;
                    if (n < 40) 
                    {
                        printf("%.2f", n * m);
                    }    
                    else if (n >= 40 && n <= 50)
                    { 
                        printf("%.2f", 40 * m + (n - 40) * 1.5 * m);
                    }
                    else
                    { 
                        printf("%.2f", 40 * m + 10 * 1.5 * m + (n - 50) * 2 * m);
                    }    
                    return 0;
                }
                //这是比较简单的写法,其他的比较难,所以就不出示了
                //老规矩不用❤️ 😄 
                //已AC,0.0s过
                
                • 1
                  @ 2022-8-23 13:42:19

                  这题判断挺简单的,就是输出有点难。代码有亿点长,理解一下。 有三种可能(见代码)

                  #include <bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                      double a, b;
                      cin >> a >> b;
                      if (a < 40)
                      {
                          cout << fixed << setprecision(2) << a * b;
                      }
                      else if (a >= 40 && a <= 50)
                      {
                          cout << fixed << setprecision(2) << 40 * b + (a - 40) * 1.5 * b;
                      }
                      else
                      {
                          cout << fixed << setprecision(2) << 40 * b + 10 * 1.5 * b + (a - 50) * 2 * b;
                      }
                      return 0;
                  }
                  
                  • 0
                    @ 2023-8-4 16:44:08

                    又是一道数学题呢👀️ 上代码🎉️

                    #include <bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                        double t , m , s;//时间,每小时薪水,周薪
                        cin >> t >> m;
                         s = t * m;//前40小时
                        if (t > 40 && t <= 50) s = 40 * m  + (t - 40) * m * 1.5;
                        //40~50小时:40小时薪水+超出部分*每小时薪水*1.5
                        if (t > 50) s = 40 * m + 10 * m * 1.5 + (t - 50) * m * 2;
                        //>50小时:40小时薪水+50小时薪水+超出部分*每小时薪水*2
                        printf("%.2f",s);//被忘了保留两位小数
                        return 0;
                    }
                    
                    • 0
                      @ 2022-7-16 17:01:27
                      #include <stdio.h>//调用scanf() printf() 
                      #include <algorithm>//调用max() min()
                      using namespace std;
                      int t ;//定义变量 
                      float m ;//定义变量 
                      int main(){
                      	scanf("%d%f",&t,&m);
                      	printf("%.2f",( //"%.2f"为格式化输出2位浮点数
                      		min(40,t) * m + //40以内的工资 min(40,t)忽略大于40的 
                      		min(max(t-40,0),10) * m * 1.5 + 
                      		//40~50的工资 max()保证不小于0 min(,t)忽略大于50的 
                      		max((t-50),0) * m * 2) 
                      		//50以上的工资 max()保证不小于0 
                      	);
                      	//看着多,实际上printf()内部只需要一行 
                      	return 0 ;
                      }
                      
                      • -1
                        @ 2022-9-24 19:48:13
                        #include<bits/stdc++.h>
                        using namespace std;
                        int main()
                        {
                        double a,b;
                        cin>>a>>b;
                        if(a<=40)
                        {
                          cout<<fixed<<setprecision(2)<<a*b;  
                        }
                        if(a>40&&a<=50)
                        {
                            cout<<fixed<<setprecision(2)<<40*b+(a-40)*1.5*b;
                        }
                        if(a>50)
                        {
                            cout<<fixed<<setprecision(2)<<40*b+10*1.5*b+(a-50)*2*b;
                        }
                            return 0;
                        }
                        
                        • -1
                          @ 2022-9-24 19:47:55
                          #include<bits/stdc++.h>
                          using namespace std;
                          int main()
                          {
                          double a,b;
                          cin>>a>>b;
                          if(a<=40)
                          {
                            cout<<fixed<<setprecision(2)<<a*b;  
                          }
                          if(a>40&&a<=50)
                          {
                              cout<<fixed<<setprecision(2)<<40*b+(a-40)*1.5*b;
                          }
                          if(a>50)
                          {
                              cout<<fixed<<setprecision(2)<<40*b+10*1.5*b+(a-50)*2*b;
                          }
                              return 0;
                          }
                          
                          • -2
                            @ 2023-11-4 20:15:02

                            没想到蓝桥杯的题目这么简单

                            #include <bits/stdc++.h>
                            using namespace std;
                            int main()
                            {
                                int n;
                                float a;
                                cin>>n>>a;
                                if (n<=40)
                                {
                                    cout<<fixed<<setprecision(2)<<n*a;
                                }
                                else if(n>40 and n<=50)
                                {
                                    cout<<fixed<<setprecision(2)<<40*a+(n-40)*a*1.5;
                                }
                                else
                                {
                                    cout<<fixed<<setprecision(2)<<40*a+10*a*1.5+(n-50)*2*a;
                                }
                                return 0;
                            }
                            
                            • -2
                              @ 2023-2-21 22:24:27
                              #include <bits/stdc++.h>
                              #include<cstdio>
                              using namespace std;
                              int main()
                              {
                                  double n,m; 
                                  cin>>n>>m;
                                  if (n < 40) 
                                  {
                                      printf("%.2f", n * m);
                                  }    
                                  else if (n >= 40 && n <= 50)
                                  { 
                                      printf("%.2f", 40 * m + (n - 40) * 1.5 * m);
                                  }
                                  else
                                  { 
                                      printf("%.2f", 40 * m + 10 * 1.5 * m + (n - 50) * 2 * m);
                                  }    
                                  return 0;
                              }
                              
                              • -3
                                @ 2022-8-30 14:27:04

                                这题是分支类型的题,虽然是蓝桥杯的题(小声),不过难度还算可以。接下来是我的思路。

                                1.输入(应该不用我多说,题目里有,建议全部用double类型😄)

                                2.3个判断(第三个写else)

                                ①a<40

                                ②a>=40&&a<=50

                                3.保留两位小数

                                代码来也!

                                #include<bits/stdc++.h>//导入万能头文件
                                using namespace std;
                                int main()
                                {
                                    double t,m;//建立时间,每小时薪水变量,分别用t和m表示
                                    cin>>t>>m;
                                    double m2=m*1.5,m3=m*2;//变了倍数以后的每小时薪水变量,这里用m2和m3表示。
                                    if(t<40)//判断t是否小于四十
                                    {
                                        printf("%.2f",t*m);
                                    }
                                    else if(t>=40&&t<=50)//判断t是否大于40并且小于50
                                    {
                                        printf("%.2f",40*m+(t-40)*m2);
                                    }
                                    else//否则t大于50
                                    {
                                        printf("%.2f",40*m+10*m2+(t-50)*m3);
                                    }
                                    return 0;
                                }
                                
                                • -6
                                  @ 2022-8-26 22:26:50
                                  #include <bits/stdc++.h>
                                  using namespace std;
                                  int main()
                                  {
                                      double a,b;
                                      cin >> a>>b;
                                      if(a <= 40)
                                      {
                                          cout <<fixed << setprecision(2)<<a*b;
                                      }
                                      else if(a > 40 && a <= 50)
                                      {
                                          cout <<fixed <<setprecision(2)<<40*b+(a-40)*b*1.5;
                                      }
                                      else if(a > 50)
                                      {
                                          cout <<fixed <<setprecision(2)<<40*b+((a-40)-(a-50))*b*1.5+(a-50)*b*2;
                                      }
                                      return 0;
                                  }
                                  
                                  • -6
                                    @ 2022-5-26 17:03:34

                                    这道题分情况去计算薪水就好

                                    1.大于50

                                    前40小时的薪水=40*每小时时薪

                                    40~50的薪水=10每小时时薪1.510* 每小时时薪 * 1.5

                                    大于50的小时薪水=(总工时50每小时时薪2(总工时-50)*每小时时薪*2

                                    2.大于40 且 小于等于50

                                    前40小时的薪水=40*每小时时薪

                                    大于40的小时薪水=(总工时-40)每小时时薪1.5*每小时时薪*1.5

                                    3.小于等于40

                                    总工时*每小时时薪

                                    if(n>50)
                                     {
                                     	cout<<fixed<<setprecision(2)<<40*a+10*a*1.5+(n-50)*a*2;
                                     }
                                     else if(n>40)
                                     {
                                     	cout<<fixed<<setprecision(2)<<40*a+(n-40)*a*1.5;
                                     }
                                     else
                                     {
                                     	cout<<fixed<<setprecision(2)<<n*a;
                                     }
                                    
                                    • -8
                                      @ 2023-8-17 15:54:17

                                      ~~~~

                                      • -10
                                        @ 2022-5-10 14:45:36

                                        保留 x 位小数

                                        方法 1

                                        • 头文件:#include <cstdio>
                                        • 语句: printf("%.xf", a);

                                        方法 2

                                        • 头文件:#include<iostream>#include<iomanip>
                                        • 语句:cout << fixed << setprecision(x) << a;

                                        注意

                                        如果题目说保留 xx 位小数,那么就按照这种方式输出就可以了。

                                        #include<iostream>
                                        #include<iomanip>
                                        using namespace std;
                                        int main()
                                        {
                                            cout << fixed << setprecision(x) << a;
                                            x代表具体要保留几位。
                                        
                                            请务必自己多敲几遍代码,这个单词比较长避免考场出到原题自己单词忘了
                                        }
                                        
                                        #include<iostream>
                                        #include <cstdio>
                                        using namespace std;
                                        int main()
                                        {
                                            printf("%.xf", a);
                                            x代表具体要保留几位。
                                        
                                            请务必自己多敲几遍代码,这个单词比较长避免考场出到原题自己单词忘了
                                        }
                                        
                                        
                                        • 1

                                        信息

                                        ID
                                        856
                                        时间
                                        1000ms
                                        内存
                                        512MiB
                                        难度
                                        6
                                        标签
                                        递交数
                                        4058
                                        已通过
                                        1380
                                        上传者