您的位置:首页 > 其它

计票统计

2015-09-12 02:39 267 查看
</pre><pre name="code" class="cpp">
#include<iostream>
#include <cstdio>
#include <cstring>
using namespace   std;
int main()
{
while(1){
cout << "请输入候选人个数::\n";
int addCandiate;
cin >> addCandiate;
if (addCandiate <= 0){
cout << "请输入合理的候选人个数!\n";
continue;
}
for (int i = 1; i <= addCandiate; ++i){
cout <<"addCandidatre xx"<< i << endl;
}
cout << "请输入候选人投票:格式:vote xx?,以getVoteResult 结束:\n";

char a[256][256] ={{0}};
int i = 0;
getchar();
while(1){
gets(a[i]);//遇到ennter健结束
if (!strcmp(a[i],"getVoteResult")){
cout << "投票结束,请查看结果:\n";
break;
}
++i;
}
int b[256] = {0};
for (int j =0; j < i; ++j){
int k = 0;
char *p =a[j];
while (*p != '\0'){
if (*p >= '1' && *p <= '9' && *p != '\0'){
int atoi_ = atoi(p);
b[atoi_]++;
break;;
}
++p;
}
}

int length1 = sizeof(b)/sizeof(b[0]);
int count_non = 0;
for (int i = 1; i <= length1;++i){
if (i <= addCandiate)
{
cout << "xx" << i << "  " << b[i] << endl;
}
else if (b[i] != 0 )
{
++count_non;
}
}
cout << count_non << endl;
cout << "投票已完成!" << endl;
cout << "是否结束:是Y 否N"<< endl;
char end1;
while (cin >> end1){
if (end1 == 'Y' || end1 == 'y'){
exit(0);
}
else if(end1 == 'N' || end1 == 'n' )
break;
else{
cout << "请重新输入是否结束";
continue;
}
}
}
return 0;
}


测试结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: