博客
关于我
【NEFU C语言阶段一】2021年计算机1班阶段考试复习 参考代码
阅读量:523 次
发布时间:2019-03-07

本文共 1479 字,大约阅读时间需要 4 分钟。

NEFU C语言阶段一考试复习内容

A 假设A字符替换问题

字符串替换是一个基础的操作,但原题样例数据可能存在问题。以下是一个简单的示例:

char s[105]; scanf("%c %c ", &a, &b); gets(s); for(int i=0; s[i]; i++) {   if(s[i]==a) s[i]=b; } printf("%s", s);

B 数组元素查找

在本题中,我们需要实现使用指针来查找数组中的元素。以下是一个示例代码:

int a[105];int main() {  int n, x, *p=a;  scanf("%d %d", &n, &x);  for(p = a; p-a < n; p++) {    if(*p == x) break;  }  printf("%p\n", p);}

C 星级穿越

这个问题涉及到素数判断以及二维数组的遍历。以下是一个示例代码:

bool is_prime(int x) {  if(x < 2) return false;  for(int i=2; i*i <= x; i++) {    if(x%i == 0) return false;  }  return true;}int main() {  int n, m, cnt=0;  scanf("%d %d", &n, &m);  int a[n][m];  for(int i=0; i < n; i++) {    for(int j=0; j < m; j++) {      a[i][j] = (is_prime(a[i][j])? 1 : 0);      cnt++;    }  }  printf("%d\n", cnt);}

D 求取最高成绩及学号

以下是一个更简洁的实现示例:

int solve(double *sc, int n, double* ave) {  *ave = 0;  int cnt=0;  for(int i=0; i < n; i++) {    if(sc[i] > *ave) {      *ave = sc[i];      cnt++;    }  }  return cnt;}int main() {  int n;  double sc[25], ave=0.0;  scanf("%d", &n);  for(int i=0; i 

E 数据标准化

以下是一个实现示例:

double fun(double x, double minx, double maxx) {  return (x - minx) / (maxx - minx) * 100;}int main() {  int n;  double sc1[105], sc2[105];  scanf("%d", &n);  for(int i=0; i 
max1) max1 = sc1[i]; if(sc2[i] < min2) min2 = sc2[i]; if(sc2[i] > max2) max2 = sc2[i]; } double score1 = fun(sc1[0], min1, max1); double score2 = fun(sc2[0], min2, max2); printf("%.2lf %.2lf\n", score1, score2);}

以上是对各个问题的简要解答和示例代码,供复习考试时参考。

转载地址:http://hqucz.baihongyu.com/

你可能感兴趣的文章
Plotly:如何使用 plotly.graph_objects 和 plotly.express 定义图形中的颜色?
查看>>
Plotly:如何使用 Python 对绘图对象条形图进行颜色编码?
查看>>
Plotly:如何使用 updatemenus 更新一个特定的跟踪?
查看>>
Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?
查看>>
Plotly:如何向烛台图添加交易量
查看>>
Plotly:如何在 plotly express 中找到趋势线的系数?
查看>>
Plotly:如何在桑基图中设置节点位置?
查看>>
pm2 start命令中的json格式详解
查看>>
pm2启动报错
查看>>
pm2通过配置文件部署nodejs代码到服务器
查看>>
PML调用PDMS内核命令研究
查看>>
PMM安装-第一篇
查看>>
PMP知识要点(第九章)
查看>>
PNETLab 镜像包官方下载太慢?不急,最新版本PNET_4.2.10分享!
查看>>
POCO库中文编程参考指南(4)Poco::Net::IPAddress
查看>>
Quartz基本使用(二)
查看>>
POC项目安装与使用指南
查看>>
Podman核心技术详解
查看>>
pods 终端安装 第三方框架的一些命令
查看>>
Podzielno
查看>>