7-1 后天(5 分)
如果今天是星期三,后天就是星期五;如果今天是星期六,后天就是星期一。我们用数字1到7对应星期一到星期日。给定某一天,请你输出那天的“后天”是星期几。
输入格式:
输入第一行给出一个正整数D
(1 ≤ D
≤ 7),代表星期里的某一天。
输出格式:
在一行中输出D
天的后天是星期几。
输入样例:
3
输出样例:
5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000
int week[] = {1, 2, 3, 4, 5, 6, 7};
int main()
{
int n;
scanf("%d", &n);
printf("%d", week[(n + 1)%7]);
return 0;
}
7-3 到底是不是太胖了(10 分)
据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。真实体重与标准体重误差在10%以内都是完美身材(即 | 真实体重 − 标准体重 | < 标准体重×10%)。已知市斤是公斤的两倍。现给定一群人的身高和实际体重,请你告诉他们是否太胖或太瘦了。
输入格式:
输入第一行给出一个正整数N
(≤ 20)。随后N
行,每行给出两个整数,分别是一个人的身高H
(120 < H < 200;单位:厘米)和真实体重W
(50 < W ≤ 300;单位:市斤),其间以空格分隔。
输出格式:
为每个人输出一行结论:如果是完美身材,输出You are wan mei!
;如果太胖了,输出You are tai pang le!
;否则输出You are tai shou le!
。
输入样例:
3
169 136
150 81
178 155
输出样例:
You are wan mei!
You are tai shou le!
You are tai pang le!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000
int main()
{
int n;
double s, t, b, c;
cin >> n;
while(n--)
{
cin >> s >> t;
t *= 0.5;
b = (s - 100) * 0.9;
c = abs(b - t);
if(c < b * 0.1){
cout << "You are wan mei!\n";
}else if(b > t){
cout << "You are tai shou le!\n";
}else{
cout << "You are tai pang le!\n";
}
}
return 0;
}
7-4 大笨钟(10 分)
微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。
下面就请你写个程序,根据当前时间替大笨钟敲钟。
输入格式:
输入第一行按照hh:mm
的格式给出当前时间。其中hh
是小时,在00到23之间;mm
是分钟,在00到59之间。
输出格式:
根据当前时间替大笨钟敲钟,即在一行中输出相应数量个Dang
。如果不是敲钟期,则输出:
Only hh:mm. Too early to Dang.
其中hh:mm
是输入的时间。
输入样例1:
19:05
输出样例1:
DangDangDangDangDangDangDangDang
输入样例2:
07:05
输出样例2:
Only 07:05. Too early to Dang.
整点是敲(h - 12)次。非整点是敲(h - 12 + 1)次。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000
int main()
{
int h, m;
scanf("%d:%d", &h, &m);
if(h < 12 || (h == 12 && m == 0)){
printf("Only %02d:%02d. Too early to Dang.", h, m);
}else if( h > 12 && m == 0){
h -= 12;
while(h--){
printf("Dang");
}
}else if(h == 12 && m > 0){
printf("Dang");
}else {
h -= 11;
while(h--){
printf("Dang");
}
}
return 0;
}
7-5 三天打鱼两天晒网(15 分)
中国有句俗语叫“三天打鱼两天晒网”。假设某人从某天起,开始“三天打鱼两天晒网”,问这个人在以后的第N天中是“打鱼”还是“晒网”?
输入格式:
输入在一行中给出一个不超过1000的正整数N。
输出格式:
在一行中输出此人在第N天中是“Fishing”(即“打鱼”)还是“Drying”(即“晒网”),并且输出“in day N”。
输入样例1:
103
输出样例1:
Fishing in day 103
输入样例2:
34
输出样例2:
Drying in day 34
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000
int main()
{
int n;
cin >> n;
if(n % 5 <= 3 && n % 5 != 0)
printf("Fishing in day %d\n", n);
else
printf("Drying in day %d\n", n);
return 0;
}
7-6 打印菱形图案(15 分)
本题要求编写程序,打印一个高度为n的、由“*”组成的正菱形图案。
输入格式:
输入在一行中给出一个正的奇数n。
输出格式:
输出由n行星号“*”组成的菱形,如样例所示。每个星号后跟一个空格。
输入样例:
7
输出样例:
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000
int main()
{
int n, m;
cin >> n;
m = (n - 1) / 2;
for(int i = 1; i <= m; i++){
for(int j = 1; j <= 2 * (m - i + 1); j++)
printf(" ");
for(int j = 1; j <= 2 * i - 1; j++){
printf("*%c",' ');
}
putchar('\n');
}
for(int i = 0; i < n; i++)
printf("*%c", ' ');
putchar('\n');
for(int i = m; i >= 1; i--){
for(int j = 1; j <= 2 * (m - i + 1); j++)
printf(" ");
for(int j = 1; j <= 2 * i - 1; j++){
printf("*%c",' ');
}
putchar('\n');
}
return 0;
}
7-7 找出不是两个数组共有的元素(20 分)
给定两个整型数组,本题要求找出不是两者共有的元素。
输入格式:
输入分别在两行中给出两个整型数组,每行先给出正整数N(≤20),随后是N个整数,其间以空格分隔。
输出格式:
在一行中按照数字给出的顺序输出不是两数组共有的元素,数字间以空格分隔,但行末不得有多余的空格。题目保证至少存在一个这样的数字。同一数字不重复输出。
输入样例:
10 3 -5 2 8 0 3 5 -15 9 100
11 6 4 8 2 6 -5 9 0 100 8 1
输出样例:
3 5 -15 6 4 1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef long long ll;
typedef pair<ll, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000
P num[450];
int m = 0;
ll ans[450], k = 0;
int used[450], l = 0;
int main()
{
ll n, t;
for(int i = 0; i < 41; i++){
num[i].s = 0;
}
cin >> n;
while(n--)
{
cin >> t;
bool flag = false;
for(int i = 0; i < m; i++){
if(num[i].f == t){
flag = true;
break;
}
}
if(flag)
continue;
num[m].f = t;
num[m++].s = 1;
}
cin >> n;
while(n--)
{
cin >> t;
bool fl = false;
for(int i = 0; i < l; i++)
if(used[i] == t){
fl = true;
break;
}
if(fl)
continue;
used[l++] = t;
bool flag = false;
for(int i = 0; i < m; i++){
if(num[i].f == t){
num[i].s++;
flag = true;
break;
}
}
if(flag)
continue;
num[m].f = t;
num[m++].s = 1;
}
for(int i = 0; i < m; i++){
if(num[i].s == 1){
ans[k++] = num[i].f;
}
}
for(int i = 0; i < k; i++){
printf("%lld%c", ans[i], i == k - 1?'\n':' ');
}
return 0;
}
7-8 螺旋方阵(20 分)
所谓“螺旋方阵”,是指对任意给定的N,将1到N×N的数字从左上角第1个格子开始,按顺时针螺旋方向顺序填入N×N的方阵里。本题要求构造这样的螺旋方阵。
输入格式:
输入在一行中给出一个正整数N(<10)。
输出格式:
输出N×N的螺旋方阵。每行N个数字,每个数字占3位。
输入样例:
5
输出样例:
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
-1 16 17 18 19 6 -1
-1 15 24 25 20 7 -1
-1 14 23 22 21 8 -1
-1 13 12 11 10 9 -1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 12
///方向向量,右下左上的顺序
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int maze[N][N];
int n;
int main()
{
cin >> n;
int x, y, num = 1;
///预处理一下边界
for(int i = 0; i <= n + 1; i++)
maze[0][i] = maze[n + 1][i] = -1;
for(int i = 0; i <= n + 1; i++)
maze[i][0] = maze[i][n + 1] = -1;
x = 1, y = 0;
for(int i = 0; ; i++){
i %= 4;///取模来实现方向循环
///一直走,直到遇到数字转弯。
while(maze[x + dx[i]][y + dy[i]] == 0){
x += dx[i];
y += dy[i];
maze[x][y] = num++;
}
if(num == n * n + 1)
break;
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++){
printf("%3d", maze[i][j]);
if(j == n)
putchar('\n');
}
return 0;
}