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

你可能感兴趣的文章
Nginx配置ssl实现https
查看>>
Nginx配置TCP代理指南
查看>>
Nginx配置代理解决本地html进行ajax请求接口跨域问题
查看>>
Nginx配置参数中文说明
查看>>
Nio ByteBuffer组件读写指针切换原理与常用方法
查看>>
NIO Selector实现原理
查看>>
NISP一级,NISP二级报考说明,零基础入门到精通,收藏这篇就够了
查看>>
NI笔试——大数加法
查看>>
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
Node.js 文件系统的各种用法和常见场景
查看>>
node.js 配置首页打开页面
查看>>