AOJ 335.三角形

Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
Total Submission: 41   Submission Accepted: 26
 
Description
一个名为PC的安大学生希望写一个程序来计算三角形的三条边长,你可以帮帮她吗?
Input
第一行是一个整数m(0<m<200),代表有m组数据。
之后m行,每行有三个整数(x<10000),三角形的三条边
Output
如果可以构成三角形,输出三边之和,否则输出"Wrong"
Sample Input
Original Transformed
2
3 4 5
3 4 9
Sample Output
Original Transformed
12
Wrong
Hint
采用结构:
……
scanf("%d",&ncase);
for(……)
{
scanf(……);
……
printf(……);
}

使用三角形两边之和大于第三边、两边之差(的绝对值)小于第三边判断三角形是否成立

 1 /*
 2 By:OhYee
 3 Github:OhYee
 4 Email:oyohyee@oyohyee.com
 5 */
 6 #include <cstdio>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <cmath>
10 #include <string>
11 #include <iostream>
12 #include <vector>
13 #include <list>
14 #include <queue>
15 #include <stack>
16 using namespace std;
17  
18 #define REP(n) for(int o=0;o<n;o++)
19  
20  
21 int main() {
22     int m,a,b,c;
23     scanf("%d",&m);
24     while(m--) {
25         scanf("%d%d%d",&a,&b,&c);
26         if(a + b > c && abs(a - b) < c) {
27             printf("%d
",a + b + c);
28         } else {
29             printf("Wrong
");
30         }
31     }
32     return 0;
33 }
原文地址:https://www.cnblogs.com/ohyee/p/5269883.html