2015年天勤考研机试模拟赛 A 推断三角形

【思路】:採用atoi转换长度。两边仅仅和大于第三边,两边之差小于第三边。

【AC代码】:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

#define MAX 100+10

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int i = 0, tri[3];
	for (i = 0;  i < 3; i++)
	{
		int j = 0, n = 0, len;
		char temp[10], length[5+1];
		cin >> n;
		while (n--)
		{
			cin >> temp;
			if (!strcmp(temp, "one"))
				length[j++] = '1';
			else if (!strcmp(temp, "two"))
				length[j++] = '2';
			else if (!strcmp(temp, "three"))
				length[j++] = '3';
			else if (!strcmp(temp, "four"))
				length[j++] = '4';
			else if (!strcmp(temp, "five"))
				length[j++] = '5';
			else if (!strcmp(temp, "six"))
				length[j++] = '6';
			else if (!strcmp(temp, "seven"))
				length[j++] = '7';
			else if (!strcmp(temp, "eight"))
				length[j++] = '8';
			else if (!strcmp(temp, "nine"))
				length[j++] = '9';
			else if (!strcmp(temp, "zero"))
				length[j++] = '0';
		}
		length[j] = '\0';
		tri[i] = atoi(length);
	}
	if ((tri[0]+tri[1]>tri[2]) && (abs(tri[0]-tri[1])<tri[2]))
		cout << "YES";
	else
		cout << "NO";
}


posted @ 2017-05-02 16:45  wzzkaifa  阅读(208)  评论(0编辑  收藏  举报