Luogu Exam Bank—Introduction 1—Sequential Structure—P5708 [Deep Foundation 2. Study 2] Triangle Area

1. Topic requirements

 Two, the code

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip> 

#include <math.h>

using namespace std;

//函数
vector<string> split(string str,char ch)
{
	vector<string> results;
	stringstream ss(str);
	string temp;
	while(getline(ss,temp,ch))
		{
			results.push_back(temp);
		}	
	return results;	
}

int main()
{
	//键盘输入
	string str;
	getline(cin,str);
	
	//切分
	vector<string> results;	
	results = split(str,' ');
	
	//字符串转浮点数
	double num1 = stod(results[0]);
    double num2 = stod(results[1]);
    double num3 = stod(results[2]);

    //计算
    double p = (num1+num2+num3)/2;
    double temp = p*(p-num1)*(p-num2)*(p-num3);
    double s = sqrt(temp);
    
    //打印
    cout << fixed << setprecision(1) << s << endl; 

    return 0;
}

Guess you like

Origin blog.csdn.net/ssismm/article/details/128497083