码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-03-19 00:55:25      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:acm

【思路】:采用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";
}


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

标签:acm

原文地址:http://blog.csdn.net/weijj6608/article/details/44431913

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!