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

你可能感兴趣的文章
php进程通信
查看>>
R&Python Data Science 系列:数据处理(2)
查看>>
php递归算法总结
查看>>
PHP递归遍历文件夹
查看>>
R&Python Data Science 系列:数据处理(1)
查看>>
php错误日志文件
查看>>
PHP错误解决:Array and string offset access syntax with curly braces is deprecated
查看>>
php隐藏手机号中间4位方法总结
查看>>
php面向对象三大特征封装、多态、继承
查看>>
php面向对象全攻略
查看>>
php面向对象的基础题
查看>>
php面试题二--解决网站大流量高并发方案(从url到硬盘来解决高并发方案总结)...
查看>>
php页面增加自选项,php-在Woocommerce中添加新的自定义默认订购目录选项
查看>>
php页面静态化技术;学习笔记
查看>>
php项目心得以及总结
查看>>
R&Python Data Science 系列:数据处理(4)长宽格式数据转换
查看>>
PHP项目集成支付宝PC端扫码支付API(国内支付)
查看>>
php预定义常量&变量
查看>>
R 集成算法③ 随机森林
查看>>
php验证码背景色设置无效
查看>>