SDUT 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).

示例输入

2iPhone 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.

提示

来源

2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛

示例程序

这是我我认为的今年省赛最简单的一道题目,但是还是出了很多问题,以后再编程的时候一定要注意细节,否则出错很难查找到错误原因

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
string s1[100000];
const string s2="inches";
double h,w,in,res,s,m;
int main()
{
    int i,j,n,t,flag,k,k2;
    int tem;
    char c;
    cin>>t;
    tem=1;
    while(t--)
    {
        i=0;
        while(1)
        {
            cin>>s1[i];
            i++;
            if(s1[i-1]==s2)
            {
                flag=i-1;
            }
            c=getchar();
            if(c=='\n')
            {
                break;
            }
        }
        n=i;
        i=flag-1;
        s=0;  k=0;
        for(j=0;j<=s1[i].size()-1;j++)
        {
            if(k==1)
            {
                s=s+(s1[i][j]-'0')*m;
                m*=0.1;
            }
            if(k==0&&s1[i][j]>='0'&&s1[i][j]<='9')
            {
                s=s*10+(s1[i][j]-'0');
            }else if(s1[i][j]=='.')
            {
                k=1;
                m=0.1;
            }
        }
        in=s;
        k2=0;
        if(fabs(in-0)<=1e-9)
        {
            res=0;
            k2=1;
        }else
        {
            i=flag+1;
            s=0;  k=0;
            for(j=0;j<=s1[i].size()-1;j++)
            {
                if(s1[i][j]=='*')
                {
                    h=s;
                    s=0;k=0;
                }
                if(k==1)
                {
                    s=s+(s1[i][j]-'0')*m;
                    m*=0.1;
                }
                if(k==0&&s1[i][j]>='0'&&s1[i][j]<='9'&&s1[i][j]!='*')
                {
                    s=s*10+(s1[i][j]-'0');
                }else if(s1[i][j]=='.')
                {
                    k=1;
                    m=0.1;
                }
            }
            w=s;
            res=sqrt((w*w)+(h*h))/in;
        }
        printf("Case %d: The ",tem); tem+=1;
        i=n-1;
  //      for(i=flag+2;i<=n-1;i++)
  //      {
            for(j=0;j<=s1[i].size()-1;j++)
            {
                if(s1[i][j]>='A'&&s1[i][j]<='Z')
                {
                    printf("%c",s1[i][j]+32);
                }else
                {
                    printf("%c",s1[i][j]);
                }
            }
            cout<<" ";
   //     }
        printf("of");
        for(j=0;j<=flag-2;j++)
        {
            cout<<" "<<s1[j];
        }
        printf("'s PPI is %.2lf.\n",res);
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值