排序

任务描述

本关任务:输入三个整数,a,b,c(均在 int 范围内),要求将这三个数从小到大排序输出。

测试说明

输入描述:三个整数 a,b,c,使用一个空格分隔。 输出描述:三个从小到大排序后的整数,以空格分隔

样例输入1:73 114 5 样例输出1:5 73 114

样例输入2:100 100 50 样例输出2:50 100 100

样例代码

// 请在下方添加代码
/********** Begin *********/
#include<iostream>

using namespace std;
int main() 
{
int a,b,c;
cin>>a>>b>>c;
if (a>=b and a>=c){
    if (b>=c){
        cout<<c<<" "<<b<<" "<<a;
    }else{
        cout<<b<<" "<<c<<" "<<a;
    }
}

else if (b>=a and b>=c){
    if (a>=c){
        cout<<c<<" "<<a<<" "<<b;
    }else{
        cout<<a<<" "<<c<<" "<<b;
    }
}
else if (c>=b and c>=a){
    if (b>=a){
        cout<<a<<" "<<b<<" "<<c;
    }else{
        cout<<b<<" "<<a<<" "<<c;
    }
}
else {
    cout<<a<<" "<<b<<" "<<c;
}




  return 0;
}
/********** End **********/

根据居民月用水量计算应收水费

任务描述

本关任务:我国是世界上严重缺水的国家之一。为了增强居民节水意识,某市自来水公司对居民用水采用以户为单位分段计费办法收费。即一月用水 10 吨以内(包括 10 吨)的用户,每吨收水费 1.5 元;一月用水超过 10 吨的用户,10 吨水仍按每吨 1.5 元收费,超过 10 吨的部分,按每吨 2 元收费。编写一个程序,输入某用户居民月用水量(单位:吨),输出应收水费(单位:元)。

测试说明

输入描述:一个大于等于 0 的浮点数 输出描述:输出计算得到的应收水费

样例输入1:5.2 样例输出1:7.8

样例输入2:18.5 样例输出2:32

样例代码


// 请在下方添加代码
/********** Begin *********/
#include<iostream>
#include<iomanip>
using namespace std;
int main() 
{
double s;
cin>>s;
if (s<=10){
    cout<<s*1.5;
}
else{
    cout<<(s-10)*2+15;
}
  return 0;
}
/********** End **********/

字符转换

任务描述

本关任务:从键盘输入一个字符,如果是大写字母,就转换为小写;如果是小写字母,就转换成大写,如果是其他字符就保持原样输出。

测试说明

输入描述:用键盘输入一个任意字符 输出描述:输出转换后的字符

样例输入1:A 样例输出1:a

样例输入2:b 样例输出2:B

样例输入3:0 样例输出3:0

样例代码

// 请在下方添加代码
/********** Begin *********/
#include<iostream>

using namespace std;
int main() 
{
char c;
cin>>c;
if (c<=90 and c>=65){
    cout<<char(c+32);
}else if (c>=97 and c<=122){
    cout<<char(c-32);
}else{
    cout<<c;
}




  return 0;
}
/********** End **********/

停车收费系统

任务描述

本关任务:设计一停车场的收费系统。停车场有 3 类汽车,分别用 3 个字母表示。C 代表轿车,B 代表客车,T 代表卡车。收费标准如下:

车辆类型 收费标准
轿车(c) 三小时内,每小时5元。三小时后,每小时10元。
客车(b) 两小时内,每小时10 元。两小时后,每小时15元。
卡车(t) 一小时内,每小时10元,一小时后,每小时15元。

测试说明

输入描述:汽车类型(c/b/t)、入库时间(自然数)和出库时间(自然数) 输出描述:应交的停车费

样例输入1:b 7 9 样例输出1:20

样例输入2:c 6 11 样例输出2:35

样例代码

// 请在下方添加代码
/********** Begin *********/
#include<iostream>

using namespace std;
int main() 
{

char t;
int a,b;
cin>>t>>a>>b;

int s = b-a;

if (t=='c'){
    if (s<=3){
        cout<<s*5;
    }else{
        cout<<(s-3)*10+15;
    }
}else if (t == 'b'){
    if (s<=2){
        cout<<s*10;
    }else{
        cout<<(s-2)*15+20;
    }
}else if (t == 't'){
    if (s<=1){
        cout<<s*10;
    }else{
        cout<<(s-1)*15+10;
    }
}



  return 0;
}
/********** End **********/