1.1编程基础之输入输出(10题)
Hello, World!
#include<iostream> using namespace std; int main() { cout<<"Hello, World!"<<endl; return 0; }
输出第二个整数
#include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<b; return 0; }
对齐输出
#include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; printf("%8d %8d %8d",a,b,c); return 0; }
输出保留3位小数的浮点数
#include<iostream> using namespace std; int main() { float a; cin>>a; printf("%.3f",a); return 0; }
输出保留12位小数的浮点数
#include<iostream> using namespace std; int main() { double a; cin>>a; printf("%.12f",a); return 0; }
空格分隔输出
#include<iostream> using namespace std; int main() { char a; float b; double c; int d; cin>>a>>d>>b>>c; printf("%c %d %f %f",a,d,b,c); return 0; }
输出浮点数
#include<iostream> using namespace std; int main() { double c; cin>>c; printf("%f\n%.5f\n%e\n%g\n",c,c,c,c); return 0; }
超级玛丽游戏
#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; }
字符菱形
#include<iostream> using namespace std; int main() { char t; cin>>t; for(int i=0;i<2;++i) { for(int j=0;j<2-i;++j)cout<<" "; for(int k=0;k<2*i+1;++k)cout<<t; cout<<endl; } for(int i=2;i>=0;--i) { for(int j=0;j<2-i;++j)cout<<" "; for(int k=0;k<2*i+1;++k)cout<<t; cout<<endl; } return 0; }
字符三角形
#include<iostream> using namespace std; int main() { char c;int i=0; cin>>c; for(;i<2;++i) { for(int j=0;j<2-i;++j)cout<<" "; for(int k=0;k<2*i+1;++k)cout<<c; cout<<endl; } for(int k=0;k<2*i+1;++k)cout<<c; return 0; }