竞赛
考级
一,买花 只要使用 if else if else 分支判断就行了 代码如下:
就是简单的 if ()if\ ()if () 语句。 Code:
【C++】我的代码 Scratch自制积木写多了 AC
题目大意 根据消费金额对应的区间折扣,输出最后的实际消费金额 考纲知识点 分支结构、基础数据类型、输入输出语句、变量的定义以及使用 解题思路 1. 如果金额不超过 100100100 元,原价买。 2. 如果金额在 101101101 元到 200200200 元,便宜 101010 元。 3. 如果金额在 201201201 元到 300300300 元,便宜 202020 元。 4. 如果金额在 301301301 元到 500500500 元,便宜 505050 元。 参考程序 时间复杂度 O(1)O(1)O(1)
代码如下
官方题解|欢乐赛#43 T1 T1 思路分析 本题主要考察分支结构,只要按照题目要求用if-else 语句把所以情况列清楚即可。 代码分析
#include<iostream> using namespace std; int main(){ int a; cin>>a; if(a<=100){ cout<<a; } else if(a>100&&a<=200){ cout<<a-10; } else if(a>200&&a<=300){ cout<<a-20; } else{ cout<<a-50; } return 0; }
#include<bits/stdc++.h>//submitRecord// using namespace std; //const int N=1e7+10; int main(){ //freopen("","r",stdin); //freopen("","w",stdout); ios::sync_with_stdio(); cin.tie(nullptr); cout.tie(nullptr); int n; cin>>n; if(n>300) cout<<n-50; else if(n>200) cout<<n-20; else if(n>100) cout<<n-10; else cout<<n; //fclose(stdin); //fclose(stdout); return 0; }
#include <stdio.h> using namespace std; int main (){ int n ; scanf("%d ",&n); if(n<=100){ printf("%d",n); } else if(n<=200){ printf("%d",n-10); } else if(n<=300){ printf("%d",n-20); } else { printf("%d",n-50); } return 0; }
#include<iostream> using namespace std; int main(){ int a; cin>>a; if(a<=100){ cout<<a<<endl; } else if(a>100&&a<=200){ cout<<a-10<<endl; } else if(a>200&&a<=300){ cout<<a-20<<endl; } else{ cout<<a-50<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a; cin>>a; if(a<=100){ cout<<a<<endl; }else if(a<=200){ cout<<a-10; }else if(a<=300){ cout<<a-20; }else { cout<<a-50; } return 0; }
#include<iostream> using namespace std; int main(){ int n; cin>>n; if(n<=100){ cout<<n; }else if(n<=200 && n>=101){ cout<<n-10; }else if(n<=300 && n>=201){ cout<<n-20; }else if(n<=500 && n>=301){ cout<<n-50; } return 0; }
提交答案之后,这里将显示提交结果~