Pixel density
Time Limit: 1000MS Memory limit: 65536K
题目描述
Pixels per inch (PPI) or pixel density is a measurement of the resolution of devices in various contexts; typically computer displays, image scanners, and digital camera image sensors. Note, the unit is not square inches. Good quality photographs usually require 300 pixels per inch when printed. When the PPI is more than 300(phone), we call it retina screen. Sunnypiggy like the retina screen very much.
But you know it is expensive for Sunnypiggy and Sunnypiggy’s own smart phone isn’t like that.
I tell you how to calculate the PPI. First we must know how big the mobile phone’s screen is. Then we get the resolution (Hp*Wp) about it. After that we calculate the diagonal resolution in pixels (Dp) and divided by diagonal size in inches. Now you get the answer.
Maybe you knew it, but Sunnypiggy’s math is very bad and he wants you to help him to calculate the pixel density of all the electronic products he dreamed.
输入
First you will get an integer T which means the number of test cases, and then Sunnypiggy will tell you the name and type of the electronic products. And you know, Sunnypiggy is a careless boy and some data aren’t standard, just like 04.00 inches or 0800*0480.
输出
Output the answers to Sunnypiggy just like the sample output. Maybe it is not a phone. Sunnypiggy like such a form, although it seems no use. The result should be rounded to 2 decimal places. When it has no screen (0.0 inches) that we define the answer is 0.00(PPI).
示例输入
2
iPhone 4S 3.5 inches 960*640 PHONE
The new iPad 0009.7 inches 2048*1536 PAD
示例输出
Case 1: The phone of iPhone 4S's PPI is 329.65.
Case 2: The pad of The new iPad's PPI is 263.92.
提示
Dp= sqrt(Wp*Wp+Hp*Hp )
Wp is width resolution in pixels, Hp is height resolution in pixels.
来源
2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
比赛的时候没有注意到最后一个字符串前会有多个空格,出了好多pe
注意 :从中间的inches字符串开始检索,同时注意输出格式
代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
using namespace std;
char str[1005][1005];
char s1[1005];
int wp,hp;
int main()
{
int cas;
cin>>cas;
getchar();
for(int l=1;l<=cas;l++)
{
double dp=0.0;
int k=0;
while(1)
{
cin>>str[k];
if(strcmp(str[k],"inches")==0)
break;
k++;
}
scanf("%d*%d",&wp,&hp);
//getchar();
gets(s1);
sscanf(str[k-1],"%lf",&dp);
printf("Case %d: The ",l);
int len=strlen(s1);
for(int i=0;i<len;i++)
{
if(s1[i]!=' ')
{
if(s1[i]>='A'&&s1[i]<='Z')
printf("%c",s1[i]+32);
else
printf("%c",s1[i]);
}
}
printf(" of");
for(int i=0;i<k-1;i++)
{
printf(" %s",str[i]);
}
printf("'s PPI is ");
if(dp==0.00)
printf("0.00.\n");
else
printf("%.2f.\n",sqrt(double(wp*wp+hp*hp))/dp);
}
return 0;
}