博客
关于我
【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/

你可能感兴趣的文章
Pytest框架环境切换实战教程!赶快收藏
查看>>
Pytest测试框架快速搭建
查看>>
pytest测试框架:最强大的自动化测试工具,让测试变得轻松有趣
查看>>
Pytest自动化测试指定执行测试用例
查看>>
python - 如何并行化python numpy中的总和计算?
查看>>
Python - 如何解析 xml 响应并将元素值存储在变量中?
查看>>
Python - 安装了扩展的远程 Webdriver
查看>>
python - 将字符串中的日期与今天的日期进行比较
查看>>
python - 数据描述符(class 内置 get/set/delete方法 )
查看>>
Python - 根据值绘制彩色网格
查看>>
Python - 正则表达式在括号之间获取数字
查看>>
python binascii.Error: Incorrect padding
查看>>
Python bool() 函数能否为无效参数引发异常?
查看>>
Python C 程序子进程在“for line in iter“处挂起
查看>>
Python Celery:自动化测试平台定时任务必备的三方库
查看>>
python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令
查看>>
Python CONNECT 4 CHECK WIN函数
查看>>
python ctypes库中动态链接库加载方式
查看>>
python cv2 图像( np array )转 HObject
查看>>
python cv2截取不规则区域图片
查看>>