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";
}


转载于:https://www.cnblogs.com/wzzkaifa/p/6796854.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值