第一个像样的程序:投票统计

学C语言过程中写的一个程序,个人感觉不错,让大家评价评价.我菜鸟一个,代码有什么不恰当的地方希望大家可以留言帮助我改进.

  1 #include <stdio.h>
  2 
  3 
  4 struct sys
  5 {
  6     int ch;
  7     char name[20];
  8 };
  9 
 10 
 11 
 12 
 13 int strthan(char a[], char b[])
 14 {    
 15     int i, iRuturn, aSize = 0, bSize = 0;
 16     while(1)
 17     {
 18         if(a[aSize++] == 0)
 19         {
 20             
 21             break;
 22         }
 23     }
 24     while(1)
 25     {
 26         if(b[bSize++] == 0)
 27         {
 28             
 29             break;
 30         }
 31     }
 32     if(aSize != bSize)
 33     {
 34         iRuturn = 0;
 35         goto fo;
 36     }
 37     for(i = 0; i < aSize; i++)
 38     {
 39         if(a[i] == b[i])
 40         {
 41             continue;
 42         }
 43         iRuturn = 0;
 44     }
 45 fo: if(iRuturn == 0)
 46     {
 47         return 0;
 48     }
 49     else
 50     {
 51         return 1;
 52     }
 53 }//DIY的字符串比较
 54 
 55 int main(void)
 56 {
 57     struct sys s[4] = {{0, "Mr.A"}, {0, "Mr.B"}, {0, "Mr.C"}, {0, "Mr.D"}};
 58     int i, o, c;
 59     char shuju[20];
 60     char *a[4] = {"Mr.A", "Mr.B", "Mr.C", "Mr.D",};
 61     printf("Welcome to good human select system:<>\n\n");
 62     printf("Candidato have Mr.A  Mr.B  Mr.C  Mr.D\n\n");
 63     printf("Please input voter number ");
 64     scanf("%d", &o);
 65     printf("\n");
 66     
 67     for(i = 1; i < o+1; i++)
 68     {
 69         printf("No.%d  voting, please write suspensory name: ", i);
 70         
 71         scanf("%s", &shuju);
 72 
 73         if(strthan(shuju, s[0].name))
 74         {
 75             s[0].ch += 1;
 76         }
 77         else if(strthan(shuju, s[1].name))
 78         {
 79             s[1].ch += 1;
 80         }
 81         else if(strthan(shuju, s[2].name))
 82         {
 83             s[2].ch += 1;
 84         }
 85         else if(strthan(shuju, s[3].name))
 86         {
 87             s[3].ch += 1;
 88         }
 89     };//记录投票数
 90     
 91     
 92     printf("\n");
 93 
 94 
 95     for(c = 0; c < 4; c++)
 96     {
 97         printf("%s have %d \n", s[c].name, s[c].ch);
 98     }
 99     //显示投票结果
100 
101         printf("\n\n");
102     
103     
104     
105     
106     if(s[0].ch < s[1].ch)
107     {
108         a[0] = a[1];
109     }
110     if(s[0].ch < s[2].ch)
111     {
112         a[0] = a[2];
113     }
114     if(s[0].ch < s[3].ch)
115     {
116         a[0] = a[3];
117     }
118     if(s[1].ch < s[2].ch)
119     {
120         a[1] = a[2];
121     }
122     if(s[1].ch < s[3].ch)
123     {
124         a[1] = a[3];
125     }
126     if(s[2].ch < s[3].ch)
127     {
128         a[2] = a[3];
129     }
130     //投票统计
131     
132     printf("No.1 is %s\n", a[0]);
133     
134     /*for(i = 0; i < 4; i++)
135     {
136     printf("%s", a[i]);
137     }*/
138      //排名次
139 
140     printf("\n");
141 }

 

转载于:https://www.cnblogs.com/g0ttl/articles/5304352.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值