题解 | #竞选社长#

竞选社长

http://www.nowcoder.com/practice/45a30e3ef51040ed8a7674984d6d1553

//竞选社长 #include<stdio.h> int main() { char ch[20] = {'0'}; for(int i = 0;i<10000;i++)//随意设循环次数 {
scanf("%c",&ch[i]); if(ch[i]=='0')//如果读取到0结束循环 { break; } } int sz = sizeof(ch)/sizeof(ch[0]);//计算数组元素 int i = 0; int numa = 0; int numb = 0; for(i =0;i<sz;i++) { if(ch[i] =='A')//A有多少个 numa++; else if(ch[i] =='B')//B有多少个 numb++; else break;//遇到0寻找结束 } if(numa<numb)//判断A与B谁多 { printf("B"); } else if(numa>numb) { printf("A"); } else printf("E");

return 0;

}

全部评论

相关推荐

这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务