【新手上路】洛谷入门1:顺序结构题单题解

偶然乘兴,步过东冈。正莺儿啼,燕儿舞,蝶儿忙


B2002 Hello,World!

代码如下:

#include<iostream>
using namespace std;
int main(){
    cout << "Hello,World!"<<endl;
    return 0;
    
}

B2025 输出字符菱形

代码如下:

#include<iostream>
#include<string>
using namespace std;

int main(){
    cout <<"  *"<<endl;
    cout <<" ***"<<endl;
    cout <<"*****"<<endl;
    cout <<" ***"<<endl;
    cout <<"  *"<<endl;
}

P1000 超级玛丽游戏

代码如下:

#include<iostream>
using namespace std;
int main()
{
    cout<<R"(                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############ )";
}

P1001 A+B Problem

代码如下:

#include<iostream>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a+b;
}

B2005 字符三角形

代码如下:

#include<iostream>
using namespace std;

int main(){
    string a;
    cin >> a;
     cout <<"  "<< a <<endl;
    cout <<" "<< a << a << a <<endl;
    cout << a << a << a << a << a <<endl;
}

P5703 【深基2.例5】苹果采购

代码如下:


#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;//读入每位同学可以分到的苹果数与同学数
    cout<<a*b<<endl;//求出它们的积,就是答案
    return 0;
}

P5704 【深基2.例6】字母转换

代码如下:

#include<iostream>
using namespace std;

int main()
{
    char a,b;
    cin >> a;
    b = a - 32;
    cout << b;
    
}

P5705 【深基2.例7】数字反转

代码如下:

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    double a;
    cin >> a;
    int A = int(a * 10);

    // 剥离各位置数字
    int cnt = 0;
    int save[10];
    for (; A > 0; A /= 10)
    {
        save[cnt++] = A % 10;//储存顺序即是反转后的顺序
    }

    //翻转数字
    double result = 0;
    for (int i = 0; i <= cnt - 1; i++)
    {
        result += save[i] * pow(10, cnt - 1 - i);
    }

    a = result / 1000;
    cout << a;

    return 0;
}

P5706 【深基2.例8】再分肥宅水

代码如下:

#include<iostream>
#include<iomanip>
using namespace std;

int main(){
    double t;
    int n;
    cin >> t >> n;
    cout << setiosflags(ios::fixed); //只有在这项设置后,setprecision才是设置小数的位数
    cout << setprecision(3) << t / n << endl << 2 * n;


    return 0;
}


P5708 【深基2.习2】三角形面积

代码如下:

#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    double a, b, c;
    cin >> a >> b >> c;
    double p = (a + b + c) / 2;
    double s = sqrt(p * (p - a) * (p - b) * (p - c));
    cout << setprecision(1) << fixed << s;
    return 0;
}


P5707 【深基2.例12】上学迟到

代码如下:

#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main() {
    int s, v, t, T = 8 * 60 - 10,h,m;
    cin >> s >> v;
    t = ceil(float(s) / v);
    if (T >= t)
    {
        T -= t;
    }
    else
    {
        T = T + 24 * 60 - t;
    }

    h = T / 60;
    m = T % 60;
    cout << setfill('0') << setw(2) << h << ":" << setw(2) << setfill('0') << m;
    return 0;
}

B2029 大象喝水

代码如下:

#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

#define pai 3.14
#define need 20 * 1000

int main()
{
    float h, r;
    cin >> h >> r;
    float buc = pai * h * pow(r, 2);
    int n = ceil(need / buc);
    cout << n;
    return 0;
}

P1425 小鱼的游泳时间

代码如下:

#include<iostream>
using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int e = (c * 60 + d - a * 60 - b) / 60;
    int f = (c * 60 + d - a * 60 - b) % 60;
    cout << e << " " << f;
    return 0;
}

P1421 小玉买文具

代码如下:

#include<iostream>
using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    int n = (a*10 + b) / 19;
    cout << n;
    return 0;
}

P3954 [NOIP 2017 普及组] 成绩

代码如下:

#include<iostream>
using namespace std;

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    int score = A*0.2 + B*0.3 + C*0.5;
    cout << score;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值