正文

二级C程序修改举例~2006-08-15 11:55:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/noip/17592.html

分享到:

  二级C程序修改1
  试题说明 :
  给定程序MODI1.C中函数 fun 的功能是:将在字符串s中出现、
  而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字
  符按原字符串中字符顺序排列,不去掉重复字符。
  例如:当s = "AABCDE",t = "BDFG"时,
  u中的字符串为"AACE"。
  请改正函数fun中的错误,使它能得出正确的结果。注意:不
  要改动main函数,不得增行或删行,也不得更改程序的结构!
  ===============================================================================
  程序 :
  #include
  #include
  #include
  /************found************/
  void fun (char *s, char *t, char u)
  { int i, j, sl, tl;
  sl = strlen(s); tl = strlen(t);
  for (i=0; i { for (j=0; j if (s[i] == t[j]) break;
  /************found************/
  if (j>tl)
  *u++ = s[i];
  }
  *u = '\0';
  )
  main()
  { char s[100], t[100], u[100];
  clrscr();
  printf("\nPlease enter string s:"); scanf("%s", s);
  printf("\nPlease enter string t:"); scanf("%s", t);
  fun(s, t, u);
  printf("the result is: %s\n", u);
  }
  所需数据 :
  #2
  @1 001010
  void fun (char *s,char *t, char *u)
  void fun (char *s,char *t, char u[])
  void fun (char *s,char *t, char u[100])
  fun (char *s,char *t, char *u)
  fun (char *s,char *t, char u[])
  fun (char *s,char *t, char u[100])
  fun (char s[],char t[], char u[])
  fun (char s[100],char t[100], char u[100])
  void fun (char s[],char t[], char u[])
  void fun (char s[100],char t[100], char u[100])
  @2 001006
  if(j>=tl)
  if(tl<=j)
  if(!(jif(!(tl>j))
  if(j==tl)
  if(tl==j
  二级C程序修改2
  试题说明 :
  给定程序MODI1.C中函数 fun 的功能是:将未在字符串s中出
  现而在字符串t中出现的字符形成一个新的字符串放在u中,u中字
  符按原字符串中字符顺序排列,不去掉重复字符。
  例如,当s = "ABCDE",t = "BDFGG"时,
  u中的字符串为"FGG"。
  请改正函数fun中的错误,使它能得出正确的结果。注意:不
  要改动main函数,不得增行或删行,也不得更改程序的结构!
  =============================================================================== 


  二级C程序修改3
  试题说明 :
  给定程序MODI1.C中函数 fun 的功能是:将既在字符串s中出
  现又在字符串t中出现的字符构成一个新的字符串放在u中,u中字
  符按原字符串中字符顺序排列,不去掉重复字符。
  例如:当s="ABBCDE",t="BDFG"时,u中的字符串为:"BBD"。
  请改正函数fun中的错误,使它能得出正确的结果。注意:不
  要改动main函数,不得增行或删行,也不得更改程序的结构!
  ===============================================================================
  程序 :
  #include
  #include
  #include
  void fun (char *s, char *t, char *u)
  { int i, j, sl, tl;
  sl = strlen(s); tl = strlen(t);
  for (i=0; i { for (j=0; j if (s[i] == t[j]) break;
  /************found************/
  if (j>=tl)
  *u++ = s[i];
  }
  /************found************/
  *u = '0';
  )
  main()
  { char s[100], t[100], u[100];
  clrscr();
  printf("\nPlease enter string s:"); scanf("%s", s);
  printf("\nPlease enter string t:"); scanf("%s", t);
  fun(s, t, u);
  printf("The result is: %s\n", u);
  }
  所需数据 :
  #2
  @1 001004
  if(jif(!(j>=tl))
  if(tl>j)
  if(!(tl<=j))
  @2 001006
  *u='\0';
  *u=0;
  (*u)='\0';
  (*u)=0;
  u[0]='\0';
  u[0]=0;
  二级C程序修改4 
  试题说明 :
  给定程序MODI1.C中函数 fun 的功能是: 将仅在字符串s中出
  现而不在字符串t中出现的字符,和仅在字符串t中出现而不在字符
  串s中出现的字符, 构成一个新字符串放在u中,u中的字符按原字
  符串中字符顺序排列,不去掉重复字符。
  例如:当s="AABCDE",t="BDFGG"时,
  u中的字符串为:"AACEFGG"。
  请改正函数fun中的错误,使它能得出正确的结果。注意:不要
  改动main函数,不得增行或删行,也不得更改程序的结构!
  程序 : 
  #include
  #include
  #include
  void fun (char *s, char *t, char *u)
  { int i, j, sl, tl;
  sl = strlen(s); tl = strlen(t);
  for (i=0; i { for (j=0; j if (s[i] == t[j]) break;
  /************found************/
  if (j *u++ = s[i];
  }
  for (i=0; i { for (j=0; j if (t[i] == s[j]) break;
  /************found************/
  if (j *u++ = t[i];
  }
  *u = '\0';
  }
  main()
  { char s[100], t[100], u[100];
  clrscr();
  printf("\nPlease enter string s:"); scanf("%s", s);
  printf("\nPlease enter string t:"); scanf("%s", t);
  fun(s, t, u);
  printf("The result is: %s\n", u);
  }
  所需数据 :

  #2
  @1 001006
  if(j=tl)
  if(!(jif(tlif(!(tlj))
  if(j==tl)
  if(tl==j)
  @2 001006
  if(j=sl)
  if(!(jif(slif(!(slj))
  if(sl==j)
  if(j==sl)

  二级C程序设计5
  试题说明 : 
  函数fun的功能是:把a数组中的n个数,和b数组中逆序的n个数
  一一对应相减、求平方,结果存在c数组中。
  例如: 当a数组中的值是:1、3、5、7、8
  b数组中的值是:2、3、4、5、8
  调用该函数后,c中存放的数据是:49、4、1、16、36
  注意: 部分源程序存在文件PROG1.C中。
  请勿改动主函数main和其它函数中的任何内容,仅在函数fun
  的花括号中填入你编写的若干语句。

  程序 :

  #include
  #include
  void fun(int a[], int b[], int c[], int n)
  {
  }
  main()
  { int i, a[100]={1,3,5,7,8}, b[100]={2,3,4,5,8}, c[100];
  clrscr();
  fun(a, b, c, 5);
  printf("The result is: ");
  for (i=0; i<5; i++) printf("%d ", c[i]);
  printf("\n");
  NONO();
  }
  NONO ( )
  {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
  FILE *rf, *wf ;
  int a[100], b[100], c[100], i, j ;
  rf = fopen("in.dat", "r") ;
  wf = fopen("bc05.dat","w") ;
  for(i = 0 ; i < 5 ; i++) {
  for(j = 0 ; j < 5 ; j++) fscanf(rf, "%d,", &a[j]) ;
  for(j = 0 ; j < 5 ; j++) fscanf(rf, "%d,", &b[j]) ;
  fun(a, b, c, 5) ;
  for(j = 0 ; j < 5 ; j++) fprintf(wf, "%d ", c[j]) ;
  fprintf(wf, "\n") ;
  }
  fclose(rf) ;
  fclose(wf) ;
  }

  所需数据 :

  @2 IN.DAT 010
  1,2,3,4,5
  6,7,8,9,10
  2,3,5,6,7

阅读(2751) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册