判断三角形
Case Time Limit: 100 MS (Others) / 200 MS (Java) Case Memory Limit: 256 MB (Others) / 512 MB (Java)
Accepted: 27 Total Submission: 41
提交查看我的提交显示标签
Problem Description
Shoutmon给萌萌兽出了一个题:给出三条线段的长度,问能否组成三角形。不过线段的长度是通过每一个数位的英文给出的。你能帮助萌萌兽吗?
Input
每个输入文件中一组数据。
分三行分别给出三条线段的长度。每行以一个整数N(1<=N<=5)开始,表示后面给出的单词个数;接下来跟着N个英文单词,每个单词表示一个数位,线段的长度由这些英文单词直接拼接而成(例如one two three代表123,one one代表11),每两个单词之间用一个空格隔开。数字0到9分别用下面十个单词表示:zero、one、two、three、four、five、six、seven、eight、nine。数据保证每条线段的长度都不为0。
Output
如果可以组成三角形,那么输出YES;否则输出NO。
Sample Input
1 one
2 one one
3 one one one
Sample Output
NO
Author
Shoutmon
Source
15浙大考研机试模拟赛
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <map>
using namespace std;
map<string, int> StrToInt;
void Init()
{
StrToInt["zero"] = 0;
StrToInt["one"] = 1;
StrToInt["two"] = 2;
StrToInt["three"] = 3;
StrToInt["four"] = 4;
StrToInt["five"] = 5;
StrToInt["six"] = 6;
StrToInt["seven"] = 7;
StrToInt["eight"] = 8;
StrToInt["nine"] = 9;
}
int GetNum(int n)
{
string str;
int res = 0;
while (n--)
{
cin >> str;
res = res * 10 + StrToInt[str];
}
return res;
}
bool Judge(int a, int b, int c)
{
if (a + b > c && abs(a - b) < c)
return true;
return false;
}
int main()
{
#ifdef _DEBUG
freopen("data.txt", "r+", stdin);
#endif // _DEBUG
std::ios::sync_with_stdio(false);
int a,b,c;
Init();
cin >> a; a = GetNum(a);
cin >> b; b = GetNum(b);
cin >> c; c = GetNum(c);
Judge(a, b, c) ? (cout << "YES") : (cout << "NO");
return 0;
}