NOI题库-1.1编程基础之输入输出题解

由于此部分太水,所以不附解析,只附代码

题目详见:http://noi.openjudge.cn/ch0101/

Hello, World!

1
2
3
4
5
6
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello, World!"<<endl;
}

输出第二个整数

1
2
3
4
5
6
7
8
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<b<<endl;
}

对齐输出

1
2
3
4
5
6
7
8
9
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
long long a,b,c;
cin>>a>>b>>c;
cout<<setw(8)<<a<<' '<<setw(8)<<b<<' '<<setw(8)<<c<<endl;
}

输出保留3位小数的浮点数

1
2
3
4
5
6
7
8
9
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float a;
cin>>a;
cout<<fixed<<setprecision(3)<<a<<endl;
}

输出保留12位小数的浮点数

1
2
3
4
5
6
7
8
9
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double a;
cin>>a;
cout<<fixed<<setprecision(12)<<a<<endl;
}

空格分隔输出

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int b;
char c;
float d;
double a;
cin>>c>>b>>d>>a;
cout<<c<<' '<<b<<' '<<fixed<<setprecision(6)<<d<<' '<<a<<endl;
}

输出浮点数

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double a;
scanf("%lf",&a);
printf("%lf\n",a);
printf("%.5lf\n",a);
printf("%e\n",a);
printf("%g\n",a);

}

字符三角形

1
2
3
4
5
6
7
8
9
10
11
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char a;
cin>>a;
printf(" %c\n",a);
printf(" %c%c%c\n",a,a,a);
printf("%c%c%c%c%c\n",a,a,a,a,a);
}

字符菱形

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char a;
cin>>a;
printf(" %c\n",a);
printf(" %c%c%c\n",a,a,a);
printf("%c%c%c%c%c\n",a,a,a,a,a);
printf(" %c%c%c\n",a,a,a);
printf(" %c\n",a);
}

超级玛丽游戏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
printf(" ********\n");
printf(" ************\n");
printf(" ####....#.\n");
printf(" #..###.....##....\n");
printf(" ###.......###### ### ### ### ###\n");
printf(" ........... #...# #...# #...# #...#\n");
printf(" ##*####### #.#.# #.#.# #.#.# #.#.#\n");
printf(" ####*******###### #.#.# #.#.# #.#.# #.#.#\n");
printf(" ...#***.****.*###.... #...# #...# #...# #...#\n");
printf(" ....**********##..... ### ### ### ###\n");
printf(" ....**** *****....\n");
printf(" #### ####\n");
printf(" ###### ######\n");
printf("############################################################## ##################################\n");
printf("#...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#\n");
printf("###########################################------------------# ###############------------------#\n");
printf("#..#....#....##..#....#....##..#....#....##################### #..#....#....#####################\n");
printf("########################################## #----------# ############## #----------#\n");
printf("#.....#......##.....#......##.....#......# #----------# #.....#......# #----------#\n");
printf("########################################## #----------# ############## #----------#\n");
printf("#.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#\n");
printf("########################################## ############ ############## ############\n");
}