题解 | #三角形的边#
三角形的边
https://www.nowcoder.com/practice/05dbd1cd43b24dbbae567b3e816d4e97
#include <stdio.h> int min(int x, int y, int z){ int min = x; if (y < min) min = y; if (z < min) min = z; return min; } int max(int x, int y, int z){ int max = x; if (y > max) max = y; if (z > max) max = z; return max; } int mid(int x, int y, int z){ //如果三个数中有相等的数,那么就是mid if (x != max(x, y,z) && x != min(x, y, z) || x == y || x == z) return x; else if(y != max(x, y,z) && y != min(x, y, z) || y == z) return y; else return z; } int main(){ int a, b, c, s; while(scanf("%d%d%d", &a, &b, &c) != EOF){ if (a == 0 || b == 0 || c == 0){ break; } else{ s = min(a, b, c) - max(a, b, c) + mid(a, b, c); printf("%d\n", s); } } return 0; }