21 条题解

  • 32
    @ 2022-8-13 21:32:40

    这题简单,我也同样提供两种方法,但是两种方法的思路一样,但方法不一样,来先看看思路吧!

    1. 输入 double 型变量 n
    2. 按照税金的条件判断,运用 if - else if - else 语句进行判断
    3. 输出的格式要是两位小数,大家都做过前面的题了,我就不多说了哈,况且下面的MOD也讲了其中的一种方法了,也可以去首页看。

    接下来就是两个方法的区别了


    方法①:在条件判断里直接输出

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        double n;
        cin >> n;
        if (n >= 10000) printf("Tax=%.2lfyuan", n * 0.05);
        else if (n >= 5000) printf("Tax=%.2lfyuan", n * 0.03);
        else if (n >= 1000) printf("Tax=%.2lfyuan", n * 0.02);
        else cout << "Tax=0.00yuan";
    	return 0;
    }
    

    方法②:把乘以的数存储在变量里再统一输出(UP推荐)

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        double n, s = 0;
        cin >> n;
        if (n >= 10000) s = 0.05;
        else if (n >= 5000) s = 0.03;
        else if (n >= 1000) s = 0.02;
        printf("Tax=%.2lfyuan", n * s);
    	return 0;
    }
    
    • 6
      @ 2023-11-13 15:00:25

      这道题其实很简单,只要先根据题目信息判断每种情况应收的税金是多少,然后再分段按照格式输出税金就行了,请看题解:(已AC,请放心食用( •̀ ω •́ )✧

      #include <iostream>
      #include <iomanip>
      using namespace std;
      int main()
      {
          double n, b;
          cin >> n;
          if (n >= 10000)
          {
              b = n / 20;
          }
          else if (n >= 5000)
          {
              b = n / 100 * 3;
          }
          else if (n >= 1000)
          {
              b = n / 50;
          }
          else
          {
              b = 0;
          }
          cout << "Tax=";
          cout << fixed << setprecision(2) << b;
          cout << "yuan";
          return 0;
      }
      

      看完后别忘了点个赞哟~

      • 2
        @ 2024-3-3 17:06:31
        #include <iostream>
        #include <iomanip>
        using namespace std;
        int main()
        {
            double n, b;
            cin >> n;
            if (n >= 10000)    //有谁想~~偷税漏税~~吗
            {
                b = n / 20;
            }
            else if (n >= 5000)
            {
                b = n / 100 * 3;
            }
            else if (n >= 1000)
            {
                b = n / 50;
            }
            else
            {
                b = 0;
            }
            cout << "Tax=" << fixed << setprecision(2) << b << "yuan";
            return 0;
        }
        
        • @ 2024-3-3 17:07:51

          我怎么打不了删除线好像又行了

      • 1
        @ 2023-8-29 11:18:19
        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            double n;//有小数用double类型
            cin >> n;
            if(n<1000)
            {
                cout << "Tax=0.00yuan";//免税直接输出0.00元;
            }
            else if(n<5000)
            {
                printf("Tax=%.2lfyuan",0.02*n)//输出2%的征税,并保留两位小数
            }
            else if(n<10000)
            {
                printf("Tax=%.2lfyuan",0.03*n);
            }
            else
            {
                printf("Tax=%.2lfyuan",0.05*n);
            }
            return 0;
        }
        点赞哦!!!
        
        • 1
          @ 2023-8-23 13:58:51
          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
              double n;
              cin >> n;
              if (n >= 10000) n = n * 0.05;
              else if (n >= 5000) n = n * 0.03;
              else if (n >= 1000) n = n * 0.02;
              else n = n * 0.00;
              printf("Tax=%.2fyuan",n);
              return 0;
          }
          点赞再开溜!
          
          • 1
            @ 2023-8-19 8:51:34
            #include <bits/stdc++.h>
            using namespace std;int main()
            {
                double n, s = 0;cin >> n;if (n >= 10000) s = 0.05;else if (n >= 5000) s = 0.03;else if (n >= 1000) s = 0.02;printf("Tax=%.2lfyuan", n * s);
            	return 0;
            }
            
            • 1
              @ 2023-8-9 10:05:00
              #include <iostream>
              using namespace std;
              int main()
              {
                  double n, s = 0;
                  cin >> n;
                  if (n >= 10000) s = 0.05;
                  else if (n >= 5000) s = 0.03;
                  else if (n >= 1000) s = 0.02;
                  printf("Tax=%.2lfyuan", n * s);
              	return 0;
              }
              
              • @ 2023-8-24 11:18:51

                头文件要换成#include <bits/stdc++.h>

            • 1
              @ 2022-5-23 20:57:39

              这个题 没什么好说的,直接使用if-else if 一一去判断就好

              根据输出样例注意输出的格式

              保留小数cout << fixed << setprecision(x) << a; x代表表示保留几位

               if(n>=10000)//定义n的时候一定要是浮点数类型,要不然会有一个样例过不去
               {
               	cout<<"Tax="<<fixed<<setprecision(2)<<n*0.05<<"yuan";
               }
              else if(n>=5000) 
               {
              	cout<<"Tax="<<fixed<<setprecision(2)<<n*0.03<<"yuan";
               }
               else if(n>=1000)
               {
               	cout<<"Tax="<<fixed<<setprecision(2)<<n*0.02<<"yuan";
               }
               else 
               {
               	cout<<"Tax=0.00yuan";
               }
              
              • 0
                @ 2024-1-28 19:09:50
                #include <bits/stdc++.h>
                using namespace std;
                int main()
                {
                    double n;
                    cin>>n;
                    if(n>10000)
                    {
                        cout<< fixed << setprecision(2) <<"Tax="<<n*0.05<<"yuan";
                    }
                    else if((n>=5000)&&(n<10000))
                    {
                        cout<< fixed << setprecision(2) <<"Tax="<<n*0.03<<"yuan";
                    }
                    else if((n<5000)&&(n>=1000))
                    {
                        cout<< fixed << setprecision(2) <<"Tax="<<n*0.02<<"yuan";
                    }
                    else
                    {
                        cout<< fixed << setprecision(2) <<"Tax="<<n-n<<"yuan";
                    }
                    return 0;
                }
                
                
                • 0
                  @ 2023-11-26 9:29:41
                  #include<bits/stdc++.h>
                  using namespace std;
                  int main(){
                   	double n;
                   	cin>>n;
                   	double a=0;
                   	if(n>=10000){
                  	 	a=n*0.05;
                  	 }
                  	 else{
                  	 	if(n>=5000){
                  		 	a=n*0.03;
                  		 }
                  		 else{
                  		 	if(n>=1000){
                  			 	a=n*0.02;
                  			 }
                  		 }
                  	 }
                  	 cout<<"Tax="<<fixed<<setprecision(2)<<a<<"yuan";
                   	return 0;
                   }
                  
                  • 0
                    @ 2023-8-4 18:49:03

                    我又来啦 这道题还比较简单 上代码🚀️

                    #include <bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                        double n;
                        cin >> n;
                        if (n >= 10000) n = n * 0.05;
                        else if (n >= 5000) n = n * 0.03;
                        else if (n >= 1000) n = n * 0.02;
                        else n = n * 0.00;
                        printf("Tax=%.2fyuan",n);
                        return 0;
                    }
                    
                    • 0
                      @ 2023-7-13 17:36:04

                      看别人都用的一个变量,感觉重复太多,我个人认为两个变量更好些

                      #include <bits/stdc++.h>
                      using namespace std;
                      int main()
                      {
                          double n,x;//一定要用double类型,否则不能AC
                          cin >> n;
                          if (n >= 10000){
                              x = n * 0.05;
                          }
                          else if ((n < 10000) && (n >= 5000)){
                              x = n * 0.03;
                          }
                          else if ((n < 5000) && (n >= 1000)){
                              x = n * 0.02;
                          }
                          else{
                              x = 0;
                          }
                          cout << fixed << setprecision(2);//保留两位小数
                          cout << "Tax=" << x << "yuan";
                          return 0;
                      }
                      
                      </span>
                      • -1
                        @ 2024-2-23 19:50:50
                        #include <bits/stdc++.h>
                        using namespace std;
                        int main()
                        {
                            double n,qsum=0;//qsum:交税总和。
                            cin>>n;
                            char a[4]={'T','a','x','='};
                            char b[4]={'y','u','a','n'};
                            if(n>=10000)
                            {
                                qsum=n*0.05;
                            }
                            if(n>=5000 && n<10000)
                            {
                                qsum=n*0.03;
                            }
                            if(n>=1000 && n<5000)
                            {
                                qsum=n*0.02;
                            }
                            if(n<1000)
                            {
                                qsum=qsum*1.00;
                            }
                            for(int i=0;i<4;i++)
                            {
                                cout<<a[i];
                            }
                            cout<<fixed<<setprecision(2)<<qsum;
                            for(int i=0;i<4;i++)
                            {
                                cout<<b[i];
                            }
                            return 0;
                        }
                        
                        • -1
                          @ 2023-8-3 20:40:13
                          #include <bits/stdc++.h>
                          using namespace std;
                          int main()
                          {
                              double n, s = 0;
                              cin >> n;
                              if (n >= 10000) s = 0.05;
                              else if (n >= 5000) s = 0.03;
                              else if (n >= 1000) s = 0.02;
                              printf("Tax=%.2lfyuan", n * s);
                          	return 0;
                          }
                          
                          • -1
                            @ 2022-9-10 19:20:14
                            
                            #include <bits/stdc++.h>
                            using namespace std;
                            int main()
                            {
                            double n;
                            cin>>n;
                            if(n>=10000)
                            {
                            cout<<"Tax="<<fixed<<setprecision(2)<<n*0.05<<"yuan";
                            }
                            else if(n>=5000)
                            {
                            cout<<"Tax="<<fixed<<setprecision(2)<<n*0.03<<"yuan";
                            }
                            else if(n>=1000)
                            {
                            cout<<"Tax="<<fixed<<setprecision(2)<<n*0.02<<"yuan";
                            }
                            else
                            {
                            cout<<"Tax=0.00yuan";
                            }
                            return 0;
                            }
                            
                            
                            • -1
                              @ 2022-8-13 21:36:52
                                  cout<<"Tax=";
                                  if(a>=10000)
                                  {
                                      printf("%.2lf",a*0.05);
                                      cout<<"yuan";
                                  }
                                  else
                                  {
                                      if(a>=5000)
                                      {
                                          printf("%.2lf",a*0.03);
                                          cout<<"yuan";
                                      }
                                      else
                                      {
                                          if(a>=1000)
                                          {
                                              printf("%.2lf",a*0.02);
                                              cout<<"yuan";
                                          }
                                          else
                                          {
                                              printf("%.2lf",a*0.0);
                                              cout<<"yuan";
                                          }
                                      }
                                  }
                              

                              再使用printf和scanf是,注意: 1,printf的格式: printf("%.xlf",s);//x为小数位数 2,scanf的格式: scanf("%.xlf",&s)//一定要有‘&’

                              • -2
                                @ 2023-8-9 20:16:51

                                简简单单干翻👎

                                #include <bits/stdc++.h> 
                                using namespace std;int main(){double long a;double b = 0;cin >> a;if (a >= 10000){ b = 0.05;}else if(a >= 5000){ b = 0.03;}else if(a >= 1000){ b = 0.02;}cout<<"Tax="<<fixed<<setprecision(2)<<(double)a * b<<"yuan"; return 0;}
                                
                                • -2
                                  @ 2023-7-16 15:27:34

                                  废话不多,上鸡汤!

                                  #include <iostream>
                                  using namespace std;
                                  int main()
                                  {
                                      double n, s = 0;
                                      cin >> n;
                                      if (n >= 10000) s = 0.05;
                                      else if (n >= 5000) s = 0.03;
                                      else if (n >= 1000) s = 0.02;
                                      printf("Tax=%.2lfyuan", n * s);
                                  	return 0;
                                  }
                                  记住!先点赞,在开溜!🎉️ 
                                  严禁在题解中偷我的题!😕
                                  仅供参考!
                                  
                                • -2
                                  @ 2023-3-29 20:56:59
                                  #include<bits/stdc++.h>
                                  using namespace std;
                                  int main()
                                  {
                                      double x;
                                      cin>>x;
                                      if (x>=10000)
                                          printf("Tax=%.2lfyuan",x*0.05);
                                      else if (x>=5000)
                                          printf("Tax=%.2lfyuan",x*0.03);
                                      else if (x>=1000)
                                          printf("Tax=%.2lfyuan",x*0.02);
                                      else
                                          cout<<"Tax=0.00yuan";
                                      return 0;
                                  }
                                  
                                  • -4
                                    @ 2022-8-30 10:39:48

                                    #include <bits/stdc++.h> using namespace std; int main() { double n; cin>>n; if(n>=10000) { cout<<"Tax="<<fixed<<setprecision(2)<<n0.05<<"yuan"; } else if(n>=5000) { cout<<"Tax="<<fixed<<setprecision(2)<<n0.03<<"yuan"; } else if(n>=1000) { cout<<"Tax="<<fixed<<setprecision(2)<<n*0.02<<"yuan"; } else { cout<<"Tax=0.00yuan"; } return 0; }

                                    信息

                                    ID
                                    1127
                                    时间
                                    1000ms
                                    内存
                                    128MiB
                                    难度
                                    5
                                    标签
                                    递交数
                                    3319
                                    已通过
                                    1310
                                    上传者