欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

第一节 练习14

程序员文章站 2022-04-04 11:11:09
...
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
    int n,oldIntAll,oldIntOk,newIntAll,newIntOk;
    float oldE,newE;
    cout << "输入:";
    cin >> n;
    
    cin >> oldIntAll >> oldIntOk;
    oldE = oldIntOk * 1.0 / oldIntAll; //升级浮点除 
    
    for (int i=1;i<=(n-1);i++){
    	cin >> newIntAll >> newIntOk;
    	newE = newIntOk * 1.0 / newIntAll; //升级浮点除 
    	
    	if(newE-oldE > 0.05){
    		cout << "better" << endl;
		}else if(oldE - newE > 0.05){
			cout << "worse" << endl;
		}else{
			cout << "same" << endl;
		}
	}
	return 0;
}
//cout << "输入:";

结果:

第一节 练习14