[NOI題庫]1.1編程基礎之輸入輸出 題解


今年NOIP居然"各有兩道題目從NOI題庫中抽取並在原題基礎上改動后使用",不好好刷題怎么行。


01 Hello, World!

      根據題意直接輸出 "Hello, World!" 即可。

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

02 輸出第二個整數

      讀入$a,b,c$,輸出$b$。

#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<b<<endl;
    return 0;
}
02.cpp

03 對齊輸出 

      輸出語句應該是 printf("%8d %8d %8d\n",a,b,c); 。

#include <cstdio>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%8d %8d %8d\n",a,b,c);
    return 0;
}
03.cpp

04 輸出保留3位小數的浮點數

      輸出語句應該是 printf("%.3f\n",x); 

#include <cstdio>
using namespace std;
int main()
{
    double x;
    scanf("%lf",&x);
    printf("%.3f\n",x);
    return 0;
}
04.cpp

05 輸出保留12位小數的浮點數

      輸出語句應該是 printf("%.12f\n",x); ,並且變量x必須是 double 類型的。

#include <cstdio>
using namespace std;
int main()
{
    double x;
    scanf("%lf",&x);
    printf("%.12f\n",x);
    return 0;
}
05.cpp

06 空格分隔輸出

      注意輸入輸出順序。

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    char a;
    int b;
    float c;
    double d;
    cin>>a>>b>>c>>d;
    printf("%c %d %f %f\n",a,b,c,d);
    return 0;
}
06.cpp

07 輸出浮點數

      這個題目向我們展示了 printf("%g\n",x); 這條語句的神奇之處。根據百度,這樣做可以省略所有無意義的0,而 printf("%f\n",x); 會固定輸出6位小數。

#include <cstdio>
using namespace std;
int main()
{
    double x;
    scanf("%lf",&x);
    printf("%f\n%.5f\n%e\n%g\n",x,x,x,x);
    return 0;
}
07.cpp

08 字符三角形

      注意每行末無空格。

#include <cstdio>
using namespace std;
int main()
{
    char c;
    scanf("%c",&c);
    printf("  %c\n",c);
    printf(" %c%c%c\n",c,c,c);
    printf("%c%c%c%c%c\n",c,c,c,c,c);
    return 0;
}
08.cpp

09 字符菱形

      和上題極其相似。

#include <cstdio>
using namespace std;
int main()
{
    char c;
    scanf("%c",&c);
    printf("  %c\n",c);
    printf(" %c%c%c\n",c,c,c);
    printf("%c%c%c%c%c\n",c,c,c,c,c);
    printf(" %c%c%c\n",c,c,c);
    printf("  %c\n",c);
    return 0;
}
09.cpp

10 超級瑪麗游戲

      這題很萌~耐心做就行了。(好吧我沒有原圖,隨便搜了一張)

                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###                 ###           ###           ###
                ...........               #...#               #...#         #...#         #...#
               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#
            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#
           ...#***.****.*###....          #...#               #...#         #...#         #...#
           ....**********##.....           ###                 ###           ###           ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################              ##################################
#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#
###########################################------------------#              ###############------------------#
#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################
##########################################    #----------#                  ##############    #----------#
#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#
##########################################    #----------#                  ##############    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#
##########################################    ############                  ##############    ############
#include <iostream>
using namespace std;
int main()
{
    cout<<"                ********"<<endl;
    cout<<"               ************"<<endl;
    cout<<"               ####....#."<<endl;
    cout<<"             #..###.....##...."<<endl;
    cout<<"             ###.......######              ###                 ###           ###           ###"<<endl;
    cout<<"                ...........               #...#               #...#         #...#         #...#"<<endl;
    cout<<"               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#"<<endl;
    cout<<"            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#"<<endl;
    cout<<"           ...#***.****.*###....          #...#               #...#         #...#         #...#"<<endl;
    cout<<"           ....**********##.....           ###                 ###           ###           ###"<<endl;
    cout<<"           ....****    *****...."<<endl;
    cout<<"             ####        ####"<<endl;
    cout<<"           ######        ######"<<endl;
    cout<<"##############################################################              ##################################"<<endl;
    cout<<"#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#"<<endl;
    cout<<"###########################################------------------#              ###############------------------#"<<endl;
    cout<<"#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################"<<endl;
    cout<<"##########################################    #----------#                  ##############    #----------#"<<endl;
    cout<<"#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#"<<endl;
    cout<<"##########################################    #----------#                  ##############    #----------#"<<endl;
    cout<<"#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#"<<endl;
    cout<<"##########################################    ############                  ##############    ############"<<endl;
    return 0;
}
10.cpp

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM