網(wǎng)站首頁 編程語言 正文
第一關(guān):數(shù)組倒置
程序功能是通過調(diào)用reverse()函數(shù)按逆序重新放置數(shù)組a中的元素值,請補(bǔ)全程序。
測試輸入: 0 1 2 3 4 5 6 7 8 9
預(yù)期輸出: 9 8 7 6 5 4 3 2 1 0
#include "stdio.h"
#define N 10
void reverse(int *p, int a, int b)
{
int c;
/***** 請在以下一行填寫代碼 *****/
while (a<b)
{
c=*(p+a);
/***** 請在以下一行填寫代碼 *****/
*(p+a)=*(p+b);
*(p+b)=c;
a++;
/***** 請在以下一行填寫代碼 *****/
b--;
}
}
int main()
{
int a[N], i;
for (i=0; i<N; i++)
/***** 請在以下一行填寫代碼 *****/
scanf("%d",&a[i]);
reverse(a, 0, N-1);//傳入首元素地址,首元素下表,末元素下標(biāo)
for (i=0; i<N; i++)
/***** 請在以下一行填寫代碼 *****/
printf("%d ",a[i]);
printf("\n");
return 0;
}
注意:p+1指向數(shù)組的下一個元素,而不是簡單的使使指針變量p的值+1
第二關(guān):字符排序
對某一個長度為7個字符的字符串, 除首、尾字符之外,要求對中間的5個字符按ASCII碼降序排列
測試輸入: CEAedca
預(yù)期輸出: CedcEAa
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int fun(char *s, int num)
{
char ch;
int i, j;
for(i = 1 ; i < num-1 ; i++)
for(j = i + 1 ; j < 6 ; j++)
{
/***** 請在以下一行填寫代碼 *****/
if(s[i]<s[j])
{
ch = *(s + j);
*(s + j) = *(s +i);
*(s + i) = ch;
}
}
}
int main()
{
char s[10];
scanf("%s",s);
/***** 請在以下一行填寫代碼 *****/
fun(s,7);
printf("%s",s);
return 0;
}
第三關(guān):找最長串
本關(guān)任務(wù):給定程序中函數(shù)fun的功能是從N個字符串中找出最長的那個串,并將其地址作為函數(shù)值返回。N個字符串在主函數(shù)中輸入,并放入一個字符串?dāng)?shù)組中。請改正程序中的錯誤,使它能得出正確結(jié)果。注意:不要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)。
測試輸入: a bb ccc dddd eeeee
預(yù)期輸出:
The 5 string :
a
bb
ccc
dddd
eeeee
The longest string :
eeeee
#include <stdio.h>
#include <string.h>
#define N 5
#define M 81
/***** 以下一行有錯誤 *****/
char* fun(char (*sq)[M])
{
int i; char *sp;
sp=sq[0];
for(i=0;i<N;i++)
if(strlen(sp)<strlen(sq[i]))
sp=sq[i];
/***** 以下一行有錯誤 *****/
return sp;
}
int main()
{
char str[N][M], *longest; int i;
for(i=0; i<N; i++)
scanf("%s",str[i]);
printf("The %d string :\n",N);
for(i=0; i<N; i++)
puts(str[i]);
longest=fun(str);
printf("The longest string :\n");
puts(longest);
return 0;
}
第四關(guān):星號轉(zhuǎn)移
規(guī)定輸入的字符串中只包含字母和*號。給定程序的功能是將字符串中的前導(dǎo)*號全部移到字符串的尾部。請將程序補(bǔ)充完整,使其能正確運行得出結(jié)果。
測試輸入: ***abcd
預(yù)期輸出: abcd***
#include <stdio.h>
void fun( char *a )
{
int i=0,n=0;
char *p;
p=a;
while (*p=='*')
{
n++; //統(tǒng)計字符串中前導(dǎo)*號的個數(shù)
p++;
}
while(*p)
{
a[i]=*p; //把前導(dǎo)*號之后的字符全部前移
i++;
p++;
}
while(n!=0)
{
a[i]='*'; //把統(tǒng)計*號個數(shù)補(bǔ)到字符串的末尾
i++;
n--;
}
a[i]='\0';
}
int main()
{
char s[81];
int n=0;
scanf("%s",s);
fun(s);
printf("The string after oveing: \n");
puts(s);
return 0;
}
原文鏈接:https://blog.csdn.net/m0_73222051/article/details/127895610
相關(guān)推薦
- 2022-09-25 ORACLE數(shù)據(jù)庫數(shù)據(jù)泵的導(dǎo)入導(dǎo)出
- 2022-09-03 python四則運算表達(dá)式求值示例詳解_python
- 2021-12-06 Go語言實現(xiàn)一個簡單生產(chǎn)者消費者模型_Golang
- 2022-07-22 如何處理SQL Server中附加數(shù)據(jù)庫時出現(xiàn)的錯誤
- 2023-04-10 Python中figure與axies繪圖有哪些不同_python
- 2022-03-14 has been blocked by CORS policy: Response to prefl
- 2023-12-15 elementui前端flex布局兼容IE10瀏覽器常用屬性使用
- 2022-06-28 ES6基礎(chǔ)語法之字符串?dāng)U展_基礎(chǔ)知識
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支