鱼C论坛

 找回密码
 立即注册
查看: 2192|回复: 4

C语言求帮助

[复制链接]
发表于 2016-1-2 14:10:18 | 显示全部楼层 |阅读模式
10鱼币
输入两个数码的英文,求其和值。

Sample Input  

5
zero one
two three
four five
six seven
eight nine


  

Sample Output  

1
5
9
13
17


  
只需要思路就好

最佳答案

查看完整内容

这样可以吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-2 14:10:19 | 显示全部楼层
这样可以吗
  1. #include<stdio.h>
  2. #include <string.h>

  3. typedef struct
  4. {
  5.         char string [10];
  6.         char value;
  7. } TAB;

  8. void dispose_string (TAB tab[], //需要tab的地址
  9.         char *a, char *b, //a b 字符串的地址
  10.         int *x, int *y); //x y 为返回的对应的数字

  11. int main()
  12. {
  13.         TAB tab[10] = {{ "zero", 0 }, { "one", 1 }, { "two", 2 },{ "three", 3 } ,{ "four", 4 } ,{ "five", 5 } ,{ "six", 6 } ,{ "seven", 7 } ,{ "eight", 8 } ,{ "nine", 9 } };
  14.         char a[10], b[10]; //加数和被加数
  15.         int x = 0, y = 0; //转换后的加数和被加数


  16.         printf ("请输入:");
  17.         scanf ("%s %s", &a, &b);
  18.         //这里应该检查a b的值


  19.         dispose_string (tab, a, b, &x, &y);

  20.         printf ("%s和%s的和为:%d\n", a, b, x + y);

  21.         return(0);
  22. }

  23. void dispose_string(TAB tab[], //需要tab的地址
  24.         char *a, char *b, //a b 字符串的地址
  25.         int *x, int *y) //x y 为返回的对应的数字
  26. {
  27.         int i, k;

  28.         for (i = 0; i < 10; i++)
  29.         {
  30.                 if (strcmp (tab[i].string,a) == 0)
  31.                 {
  32.                         *x = tab[i].value;
  33.                 }
  34.         }//应该处理一下没有找到的情况

  35.         for (k = 0; k < 10; k++)
  36.         {
  37.                 if (strcmp(tab[k].string, b) == 0)
  38.                 {
  39.                         *y = tab[k].value;
  40.                 }
  41.         }
  42. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-2 16:43:11 | 显示全部楼层
只有10以内的吗?10以内的话就用map映射一下就好了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-1-2 22:53:42 | 显示全部楼层
真6 ,谢谢你,不过以后思路就可以啦
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-5 07:23:31 From FishC Mobile | 显示全部楼层
全部宏定义不就完了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-21 17:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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