NOI / 1.1编程基础之输入输出
01:Hello, World!
答:
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"Hello, World!";
return 0;
}
02:输出第二个整数
答:
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<b;
return 0;
}
03:对齐输出
答:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
// 可以三行合并为一行写完,不过太长了
cout << setw(8) << a << ' ';
cout << setw(8) << b << ' ';
cout << setw(8) << c;
return 0;
}
04:输出保留3位小数的浮点数
答
#include<iostream>
using namespace std;
int main(){
float a;
cin>>a;
printf("%0.3f",a);
return 0;
}
05:输出保留12位小数的浮点数
答:
#include<iostream>
using namespace std;
int main(){
double a;
cin>>a;
printf("%0.12f",a);
return 0;
}
06:空格分隔输出
答
#include<iostream>
using namespace std;
int main()
{
int b;
char c;
float e;
double a;
cin>>c>>b>>e>>a;
cout<<c<<" "<<b<<" ";
printf("%0.6f ",e);
printf("%0.6f ",a);
return 0;
}
07:输出浮点数
答
#include <iostream>
using namespace std;
int main()
{
double f;
scanf("%lf", &f);
printf("%f\n%.5f\n%e\n%g", f, f, f, f);
return 0;
}
08:字符三角形
答
#include<iostream>
using namespace std;
int main()
{
char a;
cin>>a;
cout<<" "<<a<<endl;
cout<<" "<<a<<a<<a<<endl;
cout<<a<<a<<a<<a<<a<<endl;
return 0;
}
09:字符菱形
答
#include<iostream>
using namespace std;
int main()
{
char a;
cin>>a;
cout<<" "<<a<<endl;
cout<<" "<<a<<a<<a<<endl;
cout<<a<<a<<a<<a<<a<<endl;
cout<<" "<<a<<a<<a<<endl;
cout<<" "<<a<<endl;
return 0;
}
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;
}