Acall气象局最近十分繁忙,因为他们要统计繁杂的温度数据:华氏温度、摄氏温度。所以请你帮忙统计: 1、统计所有输入温度的平均温度,以华氏温度表示。 2、统计高温天气的天数(高温天气指:温度>=h,h可能是华氏温度或摄氏温度)。 3、统计低温天气的天数(低温天气指:温度<=l,l可能是华氏温度或摄氏温度)。
输入格式
第一行为n,表示有n个温度数据(1<=n<=1000)
第二行为h,l,表示高温、低温(可能是华氏温度或者摄氏温度),保证转化后的h>l,两个温度之间可能有一个或多个空格,也可能没有空格。
第三行开始为n个温度数据,摄氏温度用xC表示;华氏温度用xF表示。保证-2000<=x<=2000。每两个温度之间可能有一个或多个空格,也可能没有空格,但保证x和F(C)之间没有空格。
保证所有输入的温度为整数。
输出格式
第一行输出平均温度,以华氏温度表示,如平均温度为x,输出xF。其中x保留3位小数。
第二行依次输出高温天气的天数和低温天气的天数。
输入样例
3
60F10C
100F9C 120F
输出样例
89.400F
2 1
// Q704536.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
double Conv2F(int c)
{
return c*1.8f+32;
}
double inputT()
{
double t;
char str[10];
char sy;
int i = 0;
char ch;
while (true)
{
ch = getchar();
if (ch >= '0' && ch <= '9') break;
}
while (true)
{
str[i++] = ch;
ch = getchar();
if (ch == 'C' || ch == 'F')
{
sy = ch;
str[i] = '\0';
break;
}
}
t = atoi(str);
if (sy == 'C') t = Conv2F(t);
return t;
}
int _tmain(int argc, _TCHAR* argv[])
{
int n;
double l, h, sum = 0.0;
int ln = 0, hn = 0;
scanf("%d", &n);
h = inputT();
l = inputT();
for (int i = 0; i < n; i++)
{
double t = inputT();
if (t >= h) hn++;
if (t <= l) ln++;
sum += t;
}
printf("%.3lfF\n", sum / (double)n);
printf("%d %d", hn, ln);
return 0;
}
如果问题得到解决,麻烦点下我回答右边的采纳,谢谢