首页 > 试题广场 >

竞选社长

[编程题]竞选社长
  • 热度指数:39461 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
假设你们社团要竞选社长,有两名候选人分别是A和B,社团每名同学必须并且只能投一票,最终得票多的人为社长.

输入描述:
一行,字符序列,包含A或B,输入以字符0结束。


输出描述:
一行,一个字符,A或B或E,输出A表示A得票数多,输出B表示B得票数多,输出E表示二人得票数相等。
示例1

输入

ABBABBAAB0

输出

B
头像 小浩博客
发表于 2021-08-15 20:50:30
解法二:(我的解法都是用最朴素的C语言写的,基本功) include<stdio.h> int main(){ int a = 0; int b = 0; char ch = 0; while (scanf("%c", &ch) != 展开全文
头像 牛客161598119号
发表于 2021-12-09 17:28:37
#include<stdio.h> int main(void) { char s; int coutA=0,coutB=0; while((s=getchar())!='0')//关键是要看输入符号结束的设定 { if(s=='A') 展开全文
头像 迷茫的猫头鹰上岸了
发表于 2022-09-19 17:11:46
#include <stdio.h> int main()  {   char arr[100]={0};   int i=0;    int acount 展开全文
头像 Zerone·
发表于 2022-05-27 17:04:36
">int main() { char n; int a = 0, b = 0; while (scanf("%c", &n) != EOF) { if (n == '0') break; if (n == 'A') a++; 展开全文
头像 Portia356
发表于 2021-11-17 11:55:35
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); 展开全文
头像 诗奕
发表于 2024-01-06 19:38:24
#include <stdio.h> int main() { char s=0; int count_a=0; int count_b=0; while(((s=getchar())!='0')&&s!=EOF) { 展开全文
头像 王冠与高跟鞋
发表于 2022-01-08 15:08:57
#include<stdio.h> int main() {     int a= 0,b=0,c=0;     char num[50];   & 展开全文
头像 诗奕
发表于 2024-01-06 19:51:10
#include <stdio.h> int main() {  char arr[100] = {0};    gets(arr);    int i = 0;    int flag = 0;    while(arr[i] != '0')   {       展开全文
头像 诗奕
发表于 2024-01-06 19:56:30
#include <stdio.h> int main() { char arr[100] = {0}; int ch = 0; int flag = 0; while (((ch = getchar()) != '0') && ch ! 展开全文
头像 牛客题解官
发表于 2020-06-04 16:49:29
分析: 按照题意读入多个数据,如果当前字符为0则退出循环,最后对比A,B两者的票数输出结果即可。 题解: #include <bits/stdc++.h> using namespace std; int main() { int a_count = 0, b_count = 展开全文