Google面试题 07042012 [1]

来源:互联网 发布:天猫店铺装修软件 编辑:程序博客网 时间:2024/05/21 13:59
/*Write a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error). Generate test cases for the function assuming another developer coded the function*/#include <iostream>int getTriangleType(int a, int b, int c){if(a < 0 || b < 0 || c < 0 || a + b < c || a + c < b || b + c < a)return 4;else if(a == b && b == c)return 3;else if(a == b || b == c || a == c)return 2;elsereturn 1;};int main(){int a, b, c;std::cout << "a = ";std::cin >> a;std::cout << std::endl;std::cout << "b = ";std::cin >> b;std::cout << std::endl;std::cout << "c = ";std::cin >> c;std::cout << std::endl;std::cout << "Type: " << getTriangleType(a, b, c);return 0;}

原创粉丝点击