C语言编程题85220_第1页
C语言编程题85220_第2页
C语言编程题85220_第3页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1.短信计费用手机发短信,一般一条短信资费为0.1 元,但限定每条短信的内容在 70 个字以内(包括70个字)。如果你所发送的一条短信超过了 70个字,则大多数手机会按照每 70 个字一条短 信的限制把它分割成多条短信发送。 假设已经知道你当月所发送的每条短信的字数, 试统计 一下你当月短信的总资费。#include <set>#include <map>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <a

2、lgorithm>#define ll long long#define inf 2147483647using namespace std;int n;int main()cin >> n;double ans = 0;for(int i = 1; i <= n; i+)int x;cin >> x;ans = ans + (x - 1) / 70 + 1) * 0.1;printf("%.1lfn", ans);return 0;2.集体照医学部口腔 3 班 n 位同学约定拍集体照, n 大于 1 且不超过 100 。摄影师要求同学按

3、照身高 站成两排, 保证第二排的人身高都要大于等于第一排的人, 且第二排的人数和第一排的人数 相等或者比第一排多一个人。输入 n 位同学的身高,请问第二排中身高最矮的人的身高是多少?#include <set> #include <map>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define ll long long#define inf 2147483647 usin

4、g namespace std;int n;int a105;int main()while(scanf("%d", &n)if(n = 0)return 0;for(int i = 1; i <= n; i+) cin >> ai;sort(a + 1, a + n + 1);cout << an / 2 + 1 << endl; return 0;3.1020 跳格问题有一种游戏,在纸上画有很多小方格,第一个方格为起点(S),最后一个方格为终点。有一个棋子,初始位置在起点上,棋子每次可移动一次,棋子在起点时,可向前移动一

5、个格子到 第二个方格内;棋子在其他方格内时,可根据方格内的数字 Ni 进行移动。如果 Ni 大于零, 就向前移动 Ni 个格子;如果 Ni 小于零,就向后移动 -Ni 个格子;如果 Ni 等于零,则此次 原地不动一次, 在下一步移动时可向前移动一步到下一个格子。显然, 如果仅按此方案,会 出现棋子永远移动不到终点的情形。 为防止这种情况发生, 我们规定, 当棋子再次来到它曾 经到过的方格时, 它需要原地不动一次, 在下一步移动时可向前移动一步到下一个格子。 按 此方案,棋子总能够走到终点(F)。如果给定一个方格图,试求棋子要走多少步才能从起点走到终点。(注:当然还可能会出现向前移动 Ni 个格

6、子就跑过终点了, 则把棋子放到终点上。 如果 Ni 太小,使得棋子向后移动跑过了起点,则把棋子放到起点上。)(如图所示,其中 S代表起点, F 代表终点)(只有离开后再次来到一个方格时,才算来到它曾经到过的方格, 包括起点 S) #include <set>#include <map>#include <vector> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long lon

7、g #define inf 2147483647 using namespace std; int n, ans; int a105; bool vis105; void dfs(int x) if(x < 1)x = 1;if(x > n + 2)x = n + 2;if(visx)if(ax)ans += 2; else ans += 1; dfs(x + 1);elsevisx = 1;if(x = n + 2)return; ans+;dfs(x + ax);int main()scanf("%d", &n);a1 = 1;for(int i =

8、 2; i <= n + 1; i+) cin >> ai;dfs(1);cout << ans << endl; return 0;4. 配对碱基链脱氧核糖核酸( DNA )由两条互补的碱基链以双螺旋的方式结合而成。而构成DNA 的碱基共有4种,分别为腺瞟呤(A)、鸟嘌呤(G)、胸腺嘧啶(T)和胞嘧啶(C)。我们知道,在 两条互补碱基链的对应位置上, 腺瞟呤总是和胸腺嘧啶配对, 鸟嘌呤总是和胞嘧啶配对。 你 的任务就是根据一条单链上的碱基序列,给出对应的互补链上的碱基序列。#include <set>#include <map>

9、;#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm> #define ll long long #define inf 2147483647 using namespace std;int n;string x;int main()scanf("%d", &n);for(int i = 1; i <= n; i+)cin >> x;for(int j = 0;

10、 j < x.length(); j+)if(xj = 'T') xj = 'A'else if(xj = 'A')xj = 'T'else if(xj = 'C') xj = 'G'elsexj = 'C'cout << x << endl; return 0;5. 打鱼还是晒网 中国有句俗语叫“三天打鱼两天晒网”。某人从 1990 年 1 月 1 日起开始“三天打鱼两 天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。 注意要区分闰年和不是闰

11、年的两种情况#include <set>#include <map>#include <vector>#include <cstdio> #include <cstring>#include <iostream> #include <algorithm>#define ll long long#define inf 2147483647 using namespace std;int y, m, d;int mm12 = 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3

12、1; int tot;int main()cin >> y >> m >> d;for(int i = 1990; i < y; i+)if(i % 4 = 0 && i % 100 != 0) | i % 400 = 0) tot += 366;else tot += 365;for(int i = 1; i < m; i+)if(y % 4 = 0 && y % 100 != 0) | y % 400 = 0) && i = 2) tot += 29;elsetot += mmi - 1; to

13、t += (d - 1); if(tot % 5 <= 2) puts("fishing");elseputs("sleeping"); return 0;6. 优先队列给定一个初始数字集合,对其做如下两种操作:1. 添加一个新的数字只取出其中一个。2. 将集合中当前最小的数字取出 (输出并删除) ,如果最小的数字有多个,#include <set>#include <map>#include <queue>#include <vector>#include <cstdio>#includ

14、e <cstring>#include <iostream>#include <algorithm>#define ll long long#define inf 2147483647using namespace std;int n, m;struct dataint a200005;int cnt;bool empty()return cnt = 0;void push(int x) a+cnt = x; int p = cnt;while(p > 1 && ap < ap / 2)swap(ap, ap / 2); p =

15、p / 2;int top()return a1;void down(int x)int t = x << 1;if(t > cnt)return;if(t + 1 <= cnt && at + 1 < at) t+;if(at < ax)swap(at, ax);down(t);void pop()a1 = acnt; cnt-; down(1);q;int main()cin >> n;for(int i = 1; i <= n; i+)int x;cin >> x;q.push(x);cin >>

16、; m;char opt15;for(int i = 1; i <= m; i+)scanf("%s", opt);if(opt0 = 'E')if(q.empty()puts("NULL");elsecout << q.top() << endl;q.pop();elseint x;cin >> x;q.push(x);return 0;7. 护林员盖房子 在一片保护林中,护林员想要盖一座房子来居住,但他不能砍伐任何树木。 现在请你帮他计算:保护林中所能用来盖房子的矩形空地的最大面积。#incl

17、ude <set>#include <map>#include <queue>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define ll long long#define inf 2147483647using namespace std;int n, m;int ans;int v2525;bool check(int a, int b, int c, i

18、nt d) for(int i = a; i <= c; i+) for(int j = b; j <= d; j+) if(vij)return 0;return 1;int main()cin >> n >> m;for(int i = 1; i <= n; i+) for(int j = 1; j <= m; j+)cin >> vij;for(int i = 1; i <= n; i+)for(int j = 1; j <= m; j+)for(int k = i; k <= n; k+)for(int l

19、= j; l <= m; l+)if(check(i, j, k, l)ans = max(ans, (k - i + 1) * (l - j + 1); cout << ans << endl;return 0;8. 汽车限行 为了缓解交通压力、减少空气污染, B 市市政府决定在工作日(周一至周五)对机动车进行 限行,每辆机动车每周将有一个工作日不能出行,但周末不限行。假设该政策从 2000 年 1 月 1 日起开始执行。限行安排为:尾号为 1 和 6:周一限行尾号为 2 和 7:周二限行尾号为 3 和 8:周三限行尾号为 4 和 9:周四限行尾号为 5、0 和

20、字母:周五限行已知 2000 年 1 月 1 日为周六, 现在给出一些日期和车牌号, 求问该机动车在该天是否限行。#include <set>#include <map>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm> #define ll long long #define inf 2147483647 using namespace std;int T;int y, m, d

21、;int mm12 = 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31;int main() cin >> T; while(T-) char ch; cin >> y >> ch >>m >> ch >> d;string s; cin >> s; int day, tot = 0; if(s5 > '9' | s5 < '0')day = 5; else day = (s5 - '0') % 5; if

22、(day = 0)day = 5; for(int i = 2000; i < y; i+) if(i % 4 = 0 && i % 100 != 0) | i % 400 = 0) tot += 366;else tot += 365;for(int i = 1; i < m; i+)if(y % 4 = 0 && y % 100 != 0) | y % 400 = 0) && i = 2) tot += 29;elsetot += mmi - 1;tot += (d - 1);if(tot + 6 - 1) % 7 + 1 = d

23、ay) puts("yes");else puts("no"); return 0;9. 人工智能 人工智能一直是计算机学所追求的一个很高的境界, 全世界的计算机学家们至今仍在不断努 力力求达到这个境界。这道题也跟“人工智能”有关。学过初中物理的同学都应该知道物理学中的这个公式P (功率)=U (电压)* I (电流)。如果给定其中的任意两个值,第三个值都是很容易求的,这个就是本题的任务。#include <set>#include <map>#include <vector>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>#define ll long long#define inf 2147483647 using namespace std; int T;string s;map<char, double> mp;double get(int x)double v = 0, t = 1;for(int i = x; i < s.length();

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论