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

你可能感兴趣的文章
Spring源码学习(二):Spring容器之prepareContext和BeanFactoryPostProcessor的介绍
查看>>
PatchMatchStereo可能会需要的Rectification
查看>>
Path does not chain with any of the trust anchors
查看>>
Path形状获取字符串型变量数据
查看>>
PAT甲级——1001 A+B Format (20分)
查看>>
Skywalking原理
查看>>
PAT甲级——1006 Sign In and Sign Out (25分)
查看>>
PAT甲级——1007 Maximum Subsequence Sum (25分)
查看>>
PAT甲级——1009 Product of Polynomials (25分)(最后一个测试点段错误)
查看>>
Spring对jdbc的支持
查看>>
vagrant 的安装
查看>>
PayPal网站付款标准版(for PHP)
查看>>
Paystack Android SDK 集成与使用指南
查看>>
pbf格式详解,javascript加载导出pbf文件示例
查看>>
PBOC2.0与3.0的区别
查看>>
PbootCMS entrance.php SQL注入漏洞复现
查看>>
PbootCMS 前台RCE漏洞复现
查看>>
PBT
查看>>
PB级分析型数据库ClickHouse的应用场景和特性
查看>>
pc3-12800
查看>>