zoukankan      html  css  js  c++  java
  • 2012山东省ACM省赛-Pixel density

    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.

     

    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。
     
     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.
    ");//别忘了题目所给条件
    48         else
    49         {
    50              ans=(sqrt(a*a+b*b))/inch;
    51             printf("%.2lf.
    ",ans);
    52         }
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    Objective-C Memory Management Being Exceptional 异常处理与内存
    Objective-C Memory Management 内存管理 2
    c语言全局变量与局部变量(当变量重名时)的使用情况
    c语言指针字符串与字符数组字符串的区别
    c语言数组不同初始化方式的结果
    补码的用途
    struts2框架加载配置文件的顺序
    CSS盒子模型
    基于注解整合struts2与spring的时候如果不引入struts2-spring-plugin包自动装配无效
    @Resource注解省略name属性后的行为
  • 原文地址:https://www.cnblogs.com/youdiankun/p/3712042.html
Copyright © 2011-2022 走看看