前言
無
题目
1.时间间隔
描述
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
输入
输入包括两行。
第一行为时间点1。
第二行为时间点2。
输出
以“小时:分钟:秒”的格式输出时间间隔。格式参看输入输出。
例
输入:
12:01:12
13:09:43
输出:
01:08:31
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> int main() { int a1, b1, c1, a2, b2, c2, t1, t2, t3, a, b, c; scanf("%d:%d:%d", &a1, &b1, &c1); scanf("%d:%d:%d", &a2, &b2, &c2); t1 = a1 * 3600 + b1 * 60 + c1; t2 = a2 * 3600 + b2 * 60 + c2; if (t1 > t2) { t3 = t1 - t2; } else { t3 = t2 - t1; } a = t3 / 3600; b = t3 / 60 % 60; c = t3 % 60; printf("%02d:%02d:%02d", a, b, c); return 0; }
提示
解析
2.什么是鞍点?
描述
尝试寻找一个二维数组中的鞍点,即该位置上的元素在该行上最大,在该列上最小。如果没有鞍点,则输出“no exists”。
输入
第一行输入n ,第2至第n+1行,输入n×n的二维数组
输出
鞍点的值或提示信息。
例
输入:
3
1 2 3
4 5 9
6 7 8
输出:
3
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> #define N 100 int a[N][N]; int Min(int a[][N], int m, int n, int r) { int i, p = 0; for (i = 0; i < m; i++) { if (a[p][r] > a[i][r]) p = i; } return p; } int main() { int m, n, i, j; cin >> m; n = m; for (i = 0; i < m; i++) for (j = 0; j < n; j++) { cin >> a[i][j]; } int max, r = 0, c, num = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (a[i][r] < a[i][j]) r = j; } max = a[i][r]; c = Min(a, m, n, r); if (c == i) { printf("%d", a[i][r]); num++; } } if (num == 0) { printf("no exists"); } return 0; }
提示
1≤n≤10
解析
3.各位数字之和排序
描述
给定n个正整数,根据各位数字之和从小到大进行排序。
输入
输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。n≤10
输出
输出每组排序的结果。
例
输入:
3 230 59 110
5 199 220 108 235 120
0
输出:
110 230 59
120 220 108 235 199
代码
#include <stdio.h> int f(int n) { int s=0; do { s=s+n%10; n=n/10; } while(n); return s; } int sort(int a[],int n) { int i,j,t; for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(f(a[j])>f(a[j+1])) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } } int main() { int n,i; int a[100]; while(scanf("%d",&n), n) { for(i=0; i<n; i++) scanf("%d",&a[i]); sort(a,n); for(i=0; i<n; i++) { if(i==0) printf("%d",a[i]); else printf(" %d",a[i]); } printf("\n"); } return 0; }
提示
解析
4.删除指定字符
描述
从键盘输入一个字符串str和一个字符c,删除str中的所有字符c并输出删除后的字符串str。
输入
第一行是一个字符串,不超过100个字符,可能会有空格;
第二行是一个字符。
输出
删除指定字符后的字符串。
例
输入:
sdf$
$
输出:
sdfsdf
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> int main() { char str[105]; char c; int i; cin.getline(str, 105); scanf("%c", &c); int l = strlen(str); for (i = 0; i < l; i++) { if (str[i] != c) { cout << str[i]; } } return 0; }
提示
解析
5.鲁东信电的密码
描述
输入一个字符串和数字m,编写程序,将输入的字符串译成密码,译码规律是:用原来的字母后面的第m个字母代替原来的字母。如当m=4时,将“China”译成“Glmre”
输入
两行
第一行是数字m
第二行是字符串,字符串的长度小于等于200000位
输出
翻译后的密码
例
输入:
4
China
输出:
Glmre
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> char s[200005]; int main() { int n; scanf("%d\n", &n); cin.getline(s, 200005); for (int i = 0; s[i] != '\0'; i++) { if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = (s[i] + n - 'A') % 26 + 'A'; } if (s[i] >= 'a' && s[i] <= 'z') { s[i] = (s[i] + n - 'a') % 26 + 'a'; } } cout << s; return 0; }
提示
(字母z的后一个字母是字母a,大写字母Z的后一个字母是A。)
解析
6.找这样的5位数
描述
有这样一些5位数,它的前两位和后两位能被数n整除,中间一位也能被n整除,例如当n=6时,12000、12012、12612等均是满足条件的数字,编程统计满足条件的数据个数并输出这些数。
输入
数字n(1≤n<10)
注意多组输入!
输出
从小到大输出满足条件的5位数,要求每行输出n个
例
输入:
输出:
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> int main() { int i, n, a = 0; while (scanf("%d", &n) != EOF) { i = 10000; while (i >= 10000 && i <= 99999) { if ((i / 1000) % n == 0 && (i / 100 % 10) % n == 0 && (i % 100) % n == 0) { cout << i; a++; if (a % n == 0) { cout << endl; } else { cout << " "; } }i++; } } return 0; }
提示
解析
7.又一学生成绩
描述
有n个学生,有m门学科,按要求完成输入输出
输入
第一行 N,M 代表 n个学生,m门学科
接下来n行 每行 m 个数, 分 别代表第i个学生的m门成绩
输出
第一行 输出每个学生的平均分(保留一位小数)
第二行 输出总分最高的学生的序号 (从输入开始1,2,3,…,n如果总分相同按从小到大输出多个序号
第三行 输出按平均分从大到小排序的结果(输出序号)
例
输入:
2 2
50 60
100 99
输出:
55.0 99.5
2
2 1
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> struct student { int xh; double cj; double zcj; double pjcj; }; student a[114514]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[j].cj; a[i].zcj = a[i].zcj + a[j].cj; a[i].xh = i+1; } } for (int i = 0; i < n; i++) { a[i].pjcj = a[i].zcj / m; } for (int i = 0; i < n; i++) { printf("%.1lf", a[i].pjcj); if (i != n - 1) { cout << " "; } } for (int i = n - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (a[j].zcj < a[j + 1].zcj) { swap(a[j], a[j + 1]); } } } cout << endl; cout << a[0].xh << endl; for (int i = 0; i < n; i++) { cout << a[i].xh; if (i != n - 1) { cout << " "; } } return 0; }
提示
解析
8. 单词统计
从键盘输入一行字符(长度小于1000),统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
输入
输入只有一行句子。仅有空格和英文字母构成。
输出
单词的个数
例
输入:
stable marriage problem Consists of Matching members
输出:
7
代码
#define _CRT_SECURE_NO_WARNINGS 1 using namespace std; #include<iostream> #include<cmath> #include<cstring> #include<algorithm> int main() { char str[1005]; int i, a, b; cin.getline(str, 1005); b = 0; for (i = 0; str[i] != '\0'; i++) { if (str[i] != ' ' && str[i + 1] == ' ') { b++; } } a = strlen(str); if (str[a - 1] != ' ') { b++; } cout << b; return 0; }
Comments NOTHING