sdut 2411 Pixel density

 

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.
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 int main()
 5 {
 6     int n,t,i,j,k,pos,lenth;
 7     double p,wp,hp,ans;
 8     char s[101][101],c;
 9     scanf("%d",&n);
10     for(t = 1; t <= n; t++)
11     {
12         for(i = 0; ; i++)
13         {
14             scanf("%s",s[i]);
15             c = getchar();没有想到输入字符,判断是否该字符串结束
16             if(c == '\n')
17             {
18                 lenth = i;
19                 break;
20             }
21         }
22         for(j = 0; j <= i; j++)
23         {
24             if(strcmp(s[j],"inches") == 0)
25             {
26                 sscanf(s[j-1],"%lf",&p);
27                 sscanf(s[j+1],"%lf*%lf",&wp,&hp);
28                 pos = j-1;
29                 break;
30             }
31         }
32         for(i = pos + 3; i <= lenth; i++)
33             for(k = 0; s[i][k] ; k++)
34             {
35                 if(s[i][k] >= 'A' && s[i][k] <= 'Z')
36                     s[i][k] = s[i][k] +32;
37             }
38         ans = sqrt(wp*wp+hp*hp);
39         printf("Case %d: The",t);
40         for(i = pos +3; i <= lenth; i++)
41             printf(" %s",s[i]);
42         printf(" of");
43         for(i = 0; i < pos-1; i++)
44             printf(" %s",s[i]);
45 
46         printf(" %s's",s[pos-1]);
47 
48         printf(" PPI is %.2lf.\n",fabs(p-0)<=1e-9?0.00:ans/p);
49     }
50     return 0;
51 
52 
53 }
54 
55 
56  


把每个长的字符串分成若干个小字符串放在二维数组中,找到"inches"所在位置,再将它左右的数字取出来计算。。。悲催啊,将字符串输错了,一直wa.以后还是复制粘贴吧。

原文地址:https://www.cnblogs.com/LK1994/p/3120258.html