牛客网-编程语言初学练习赛(第四场)题解

https://ac.nowcoder.com/acm/contest/312#question

只说可说的

D进制A+B

十六进制用%x,八进制用%o

J竞选社长

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#define PI  3.1415926
using namespace std;


int main() {
	int ch;
	int sum_a = 0, sum_b = 0;       // 分别用来计数A和B的数量
	// getchar()返回值是int类型,EOF是-1,代表文件结束
	// 这样写实现了一个字符一个字符的输入字符串,执行到文件结束,换行时停止输入
	while ((ch = getchar()) != EOF && ch != '\n') {
		if (ch == 'O') break;
		else if (ch == 'A') sum_a++;
		else if (ch == 'B') sum_b++;
	}
	if (sum_a == sum_b) cout << "E" << endl;  // 如果A的数量等于B的数量,输出E
	else printf("%s\n", sum_a > sum_b ? "A" : "B"); // 条件运算符,如果A的数量大于B的数量,输出A,否则输出B
	return 0;
}

2018.12.27  16:09  寝室

猜你喜欢

转载自blog.csdn.net/qq_43005180/article/details/85287716