目录
显示
声明
这是 拼题A(PTA)《中M2019秋C入门和进阶练习集》的习题。原题在 https://pintia.cn/problem-sets/1163286449659043840/problems/1174288506294865970 (侵删)
本人的答案仅供交流学习,请勿用于当作答案来提交!
题目描述
7-22 用天平找小球 (10 point(s))
三个球A、B、C,大小形状相同且其中有一个球与其他球重量不同。要求找出这个不一样的球。
输入格式:
输入在一行中给出3个正整数,顺序对应球A、B、C的重量。
输出格式:
在一行中输出唯一的那个不一样的球。
输入样例:
1 1 2
输出样例:
C
我的答案
/*================================================================
* Copyright (C) 2019 程序知路. All rights reserved.
*
* Filename :7-22-天平找小球.c
* Author :程序知路
* E-Mail :admin@icxzl.com
* Create Date :2019年10月25日
* Description :
================================================================*/
#include
size_t diff_index(int []);
int main() {
int weights[3];
scanf("%d %d %d", weights, &weights[1], &weights[2]);
char balls[3] = {'A', 'B', 'C'};
printf("%c", balls[diff_index(weights)]);
return 0;
}
size_t diff_index(int weights[]) {
size_t index = 0;
if (weights[0] == weights[2])
index = 1;
else if (weights[0] == weights[1])
index = 2;
return index;
}
鉴于本人的相关知识储备以及能力有限,本博客的观点和描述如有错漏或是有考虑不周到的地方还请多多包涵,欢迎互相探讨,一起学习,共同进步。
本文章可以转载,但是需要说明来源出处!
本文使用的部分图片来源于网上,若是侵权,请与本文作者联系删除: admin@icxzl.com