鱼C论坛

 找回密码
 立即注册
查看: 972|回复: 1

[已解决]小问题求助

[复制链接]
发表于 2020-1-27 14:01:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本题要求实现一个函数,统计给定字符串中英文字母、空格或回车、数字字符和其他字符的个数。
函数接口定义:void StringCount( char s[] );                        
其中 char s[] 是用户传入的字符串。函数StringCount须在一行内按照
letter = 英文字母个数, blank = 空格或回车个数, digit = 数字字符个数, other = 其他字符个数                        
的格式输出。
裁判测试程序样例:#include <stdio.h>#define MAXS 15void StringCount( char s[] );void ReadString( char s[] ); /* 由裁判实现,略去不表 */int main(){    char s[MAXS];    ReadString(s);    StringCount(s);    return 0;}/* Your function will be put here */                        
输入样例:aZ &09 Az                        
输出样例:letter = 4, blank = 3, digit = 2, other = 1

完整代码:
  1. #include <stdio.h>
  2. #define MAXS 15

  3. void StringCount( char s[] );
  4. void ReadString( char s[] ); /* 由裁判实现,略去不表 */

  5. int main()
  6. {
  7.     char s[MAXS];

  8.     ReadString(s);
  9.     StringCount(s);

  10.     return 0;
  11. }

  12. /* Your function will be put here */
  13. #include <string.h>
  14. void StringCount( char s[] )
  15. {
  16.         int i,n;
  17.         int letter=0,digit=0,blank=0,other=0;
  18.         n=strlen(s);
  19.         for(i=0;i<n;i++){
  20.                 if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')){
  21.                         letter++;
  22.                 }
  23.                 else if(s[i]>='0'&&s[i]<='9'){
  24.                         digit++;
  25.                 }
  26.                 else if(s[i]==' '||s[i]=='\n'){
  27.                         blank++;
  28.                 }
  29.                 else other++;
  30.         }
  31.         printf("letter = %d, blank = %d, digit = %d, other = %d\n",letter,blank,digit,other);
  32. }
复制代码

1.代码在OJ上提交通过了,但在Dev本地运行不通过;显示 [Error] ld returned 1 exit status;也不存在有
Dev
C程序运行之后没有关的情况;是代码有漏洞吗?

2.
void ReadString( char s[] )
;
/* 由裁判实现,略去不表 */     
裁判程序样例中的这个函数如何做用的呢?我还需要用strlen函数统计字符串长度吗?
最佳答案
2020-1-27 15:07:09
1. 由于 ReadString 函数没有定义它的函数体(函数体由裁判定义),因此在本地运行报错。

2. 你不用管裁判是如何实现的。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-1-27 15:07:09 | 显示全部楼层    本楼为最佳答案   
1. 由于 ReadString 函数没有定义它的函数体(函数体由裁判定义),因此在本地运行报错。

2. 你不用管裁判是如何实现的。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-14 01:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表