洛谷试炼day1:超级玛丽

题目背景
本题是洛谷的试机题目,可以帮助了解洛谷的使用。

建议完成本题目后继续尝试P1001、P1008。

题目描述
超级玛丽是一个非常经典的游戏。请你用字符画的形式输出超级玛丽中的一个场景。

********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############

输入格式

输出格式
如描述

输入输出样例

看到题我吓了一跳开始怀疑人生
下面是代码,总之就是复制粘贴。
方法一:

#include<iostream>
using namespace std;
int main() {

   cout<<"                ********\n"
    "               ************\n"
    "               ####....#.\n"
    "             #..###.....##....\n"
    "             ###.......######              ###            ###\n"
    "                ...........               #...#          #...#\n"
    "               ##*#######                 #.#.#          #.#.#\n"
    "            ####*******######             #.#.#          #.#.#\n"
    "           ...#***.****.*###....          #...#          #...#\n"
    "           ....**********##.....           ###            ###\n"
    "           ....****    *****....\n"
    "             ####        ####\n"
    "           ######        ######\n"
    "##############################################################\n"
    "#...#......#.##...#......#.##...#......#.##------------------#\n"
    "###########################################------------------#\n"
    "#..#....#....##..#....#....##..#....#....#####################\n"
    "##########################################    #----------#\n"
    "#.....#......##.....#......##.....#......#    #----------#\n"
    "##########################################    #----------#\n"
    "#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#\n"
    "##########################################    ############\n"<<endl;

    return 0;
}

方法二:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    cout <<setw(24)<<"********"<<endl;
    cout<<setw(27)<<"************"<<endl;
    cout<<setw(25)<<"####....#."<<endl;
    cout<<setw(30)<<"#..###.....##...."<<endl;
    cout<<setw(29)<<"###.......######"<<"              ###            ###"<<endl;
    cout<<setw(27)<<"..........."<<"               #...#          #...#"<<endl;
    cout<<setw(25)<<"##*#######"<<"                 #.#.#          #.#.#"<<endl;
    cout<<setw(29)<<"####*******######"<<"             #.#.#          #.#.#"<<endl;
    cout<<setw(32)<<"...#***.****.*###...."<<"          #...#          #...#"<<endl;
    cout<<setw(32)<<"....**********##....."<<"           ###            ###"<<endl;
    cout<<setw(32)<<"....****    *****...."<<endl;
    cout<<setw(29)<<"####        ####"<<endl;
    cout<<setw(31)<<"######        ######"<<endl;
    cout<<"##############################################################"<<endl;
    cout<<"#...#......#.##...#......#.##...#......#.##------------------#"<<endl;
    cout<<"###########################################------------------#"<<endl;
    cout<<"#..#....#....##..#....#....##..#....#....#####################"<<endl;
    cout<<"##########################################    #----------#"<<endl;
    cout<<"#.....#......##.....#......##.....#......#    #----------#"<<endl;
    cout<<"##########################################    #----------#"<<endl;
    cout<<"#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#"<<endl;
    cout<<"##########################################    ############"<<endl;
    return 0;
}

知识点:
咳咳,复习一下setw函数,setw函数是包含在iomanip头文件里面的,可以用来空格?
举个例子

cout<<setw(8)<<"C++"<<setw(6)<<"LOL"<<endl;

输出如下
C++ LOL
从开头到最后一个+结束是8个格子,从最后一个+开始(不包含)到LOL结束是6个格子。

另外
\n表示换行,\b是回退符,\r是回车符,\t是制表符,\代表反斜线,“可出来一个双引号防止误解,\f是换页符。
输出一个字符文字可用’'两个单引号,输出一个字符串可用两个”"双引号。在这里插入图片描述

发布了7 篇原创文章 · 获赞 0 · 访问量 67

猜你喜欢

转载自blog.csdn.net/zero_taeyeon/article/details/104108627
今日推荐