题目及AC代码:
121.计算火柴棒个数
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a,b,s=0;
cin>>a;
if(a==0){
cout<<6;
}
if(a==1){
cout<<2;
}
if(a==2){
cout<<5;
}
if(a==3){
cout<<5;
}
if(a==4){
cout<<4;
}
if(a==5){
cout<<5;
}
if(a==6){
cout<<6;
}
if(a==7){
cout<<3;
}
if(a==8){
cout<<7;
}
if(a==9){
cout<<6;
}
return 0;
}
122.最大数输出
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a,b,c,s=0;
cin>>a>>b>>c;
if(a>b&&a>c){
cout<<a;
}
if(b>a&&b>c){
cout<<b;
}
if(c>b&&a<c){
cout<<c;
}
return 0;
}
123.点和正方形的关系
#include<bits/stdc++.h>
using namespace std;
int main(){
double x,y;
cin>>x>>y;
if((x>=-1&&x<=1)&&(y>=-1&&y<=1)){
cout<<"yes";
}else{
cout<<"no";
}
return 0;
}
124.三角形判断
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a,b,c;
cin>>a>>b>>c;
if(a+b>c){
cout<<"yes";
}else{
cout<<"no";
}
return 0;
}
125.识别三角形
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a,b,c;
cin>>a>>b>>c;
if(a+b<=c||a+c<=b||c+b<=a){
cout<<"NO";
return0;
}
if(a==b&&b==c){
cout<<"Equilateral";
}elseif(a==b||a==c||b==c){
cout<<"Isosceles";
}elseif(c*c==a*a+b*b||a*a==c*c+b*b||b*b==a*a+c*c){
cout<<"Right";
}else{
cout<<"General";
}
return 0;
}
126.骑车与走路
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a;
double b,c;
cin>>a;
b=a/1.2;
c=a/3.0+50;
if(c>b){
cout<<"Walk";
}
if(b>c){
cout<<"Bike";
}
if(b==c){
cout<<"All";
}
return 0;
}
127.分段函数
#include<bits/stdc++.h>
using namespace std;
int main(){
double x,y;
cin>>x>>y;
if(0<=x&&x<5){
y=2.5-x;
}
if(5<=x&&x<10){
y=2-1.5*(x-3)*(x-3);
}
if(10<=x&&x<20){
y=x/2-1.5;
}
printf("%.3lf",y);
return 0;
}
128.简单算术表达式求值
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a,b;
char c;
cin>>a>>c>>b;
if(c=='+'){
cout<<a+b;
}
if(c=='-'){
cout<<a-b;
}
if(c=='*'){
cout<<a*b;
}
if(c=='/'){
cout<<a/b;
}
if(c=='%'){
cout<<a%b;
}
return 0;
}
129.计算器(简易版)
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong a,b;
char c;
cin>>a>>b>>c;
if(c=='+'){
cout<<a+b;
}
if(c=='-'){
cout<<a-b;
}
if(c=='*'){
cout<<a*b;
}
if(c=='/'){
if(b==0){
cout<<"Error!";
}else{
cout<<a/b;
}
}
return 0;
}
130.贪吃的代价
#include<bits/stdc++.h>
using namespace std;
int main(){
longlong n,a,b,s=0,c,d;
cin>>n>>a>>b;
if(n<=0||a>n||b>n){
cout<<0<<" "<<0;
return0;
}
for(int i=0;i<=n/a;i++){
for(int j=0;j<=n/b;j++){
if(i*a+j*b<=n){
if(i+j>s){
s=i+j;
c=i;
d=j;
}elseif(i+j==s){
if(i*a+b*j>=c*a+d*b){
c=i;
d=j;
}
}
}
}
}
cout<<c<<" "<<d;
return 0;
}