码迷,mamicode.com
首页 > 其他好文 > 详细

2012山东省ACM省赛-Pixel density

时间:2014-05-07 02:23:38      阅读:481      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   java   

Pixel density

题目描述

 

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.

 bubuko.com,布布扣

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.
 
题目大意:字符串取数。如第一组测试数据,长:960,宽:640,求出对角线,除以3.5(inches)。
注意题目所说如果inches=0.0,输出0.00。
 
bubuko.com,布布扣
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 char s[1001][101];
 5 char str[101];
 6 
 7 int main()
 8 {
 9     int n,i,k,m,len;
10     double a,b,inch,ans;
11     scanf("%d",&n);
12     getchar();
13     for(k=1;k<=n;k++)
14     {
15         inch=0.0;
16         for(i=0;;i++)
17         {
18             scanf("%s",s[i]);
19             if(strcmp(s[i],"inches")==0)//找到下手点
20                 break;
21         }
22         m=i;
23         sscanf(s[m-1],"%lf",&inch);//把用字符串形式表示的浮点数,写入inch中
24         scanf("%lf*%lf",&a,&b);
25         gets(str);
26         len=strlen(str);
27         printf("Case %d: The ",k);
28         for(i=0;i<len;i++)
29         {
30             if(str[i]!= )//去掉前导空格
31                 break;
32         }
33         for(;i<len;i++)
34         {
35             if(str[i]>=A&&str[i]<=Z)//这块很容易WA,可能输入的不止大写字母
36                 printf("%c",str[i]-A+a);
37             else
38                 printf("%c",str[i]);//比如是小写字母,就原样输出
39         }
40         printf(" of");
41         for(i=0;i<m-1;i++)
42         {
43             printf(" %s",s[i]);
44         }
45         printf("‘s PPI is ");
46         if(inch==0.0)
47             printf("0.00.\n");//别忘了题目所给条件
48         else
49         {
50              ans=(sqrt(a*a+b*b))/inch;
51             printf("%.2lf.\n",ans);
52         }
53     }
54     return 0;
55 }
bubuko.com,布布扣

 

2012山东省ACM省赛-Pixel density,布布扣,bubuko.com

2012山东省ACM省赛-Pixel density

标签:des   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/youdiankun/p/3712042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!