鱼C论坛

 找回密码
 立即注册
查看: 1949|回复: 2

用c语音怎么写啊?新手求助

[复制链接]
发表于 2020-6-12 06:54:23 From FishC Mobile | 显示全部楼层 |阅读模式

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

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

x
积分抽奖描述:
为回馈用户,信用卡中心举行抽奖活动,抽奖规则为:信用卡积分为特定数字的客户为幸运客户。客户已经按照积分多少排序。
输入1:以字符串形式表示的,已经排序好的客户信用卡积分列表(姓名:积分,姓名:积分)。
输入2:幸运信用积分数。
输出:中奖客户姓名。没有中奖客户输出字符串NONE;多个客户用,分割。
示例:输入1:tom:188,jim:288,mike:688,jimi:888
         输入2: 688         输出:mike
         解释:tom:188表示tom积分为188分,找到积分为688的中奖客户姓名为mike。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-6-13 10:19:16 | 显示全部楼层
结构体链表就能做,还需要吗?需要可以给你写一个
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-13 10:43:59 | 显示全部楼层
  1. #include<stdio.h>
  2. #include<stdlib.h>

  3. typedef struct user{
  4.         char name[5];
  5.         int point;
  6.         struct user *next;
  7. }User;

  8. //建立用户结构体链表
  9. void CreateUserList(User *L)
  10. {
  11.         char c;
  12.         int i, count=0;
  13.         User *p, *pre;
  14.         pre = L;
  15.         while((c = getchar()) != '\n')
  16.         {
  17.                 if(c >= 'a' && c <= 'z')
  18.                 {
  19.                         p = (User *)malloc(sizeof(User));
  20.                         p->name[0] = c;
  21.                         count = 1;
  22.                         while((c = getchar()) != ':')
  23.                         {
  24.                                 p->name[count] = c;
  25.                                 count++;
  26.                         }
  27.                         for(i=count; i<5; i++)
  28.                         {
  29.                                 p->name[i] = '#';
  30.                         }
  31.                         scanf("%d", &p->point);
  32.                         pre->next = p;
  33.                         p->next = NULL;
  34.                         pre = p;
  35.                 }
  36.         }
  37. }

  38. void PrintUserList(User *L)
  39. {
  40.         User *p;
  41.         int i;
  42.         p = L->next;
  43.         while(p != NULL)
  44.         {
  45.                 for(i=0; i<5; i++)
  46.                 {
  47.                         if(p->name[i] != '#')
  48.                                 printf("%c", p->name[i]);
  49.                 }
  50.                 printf(":%d ", p->point);
  51.                 p = p->next;
  52.         }
  53. }

  54. //查找结构体链表里对应point为输入值的那个结点
  55. void FindLuck(User *L)
  56. {
  57.         User *p;
  58.         int target, i;
  59.         p = L->next;
  60.         scanf("%d", &target);
  61.         while(p->point != target)
  62.                 p = p->next;
  63.         for(i=0; i<5; i++)
  64.         {
  65.                 if(p->name[i] != '#')
  66.                         printf("%c", p->name[i]);
  67.         }
  68. }
  69. int main()
  70. {
  71.         User L;
  72.         CreateUserList(&L);
  73.         //PrintUserList(&L);用于测试建立链表
  74.         FindLuck(&L);
  75.         return 0;
  76. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-2 15:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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