Pixel density(简单的字符串处理)

1、题目大意:

给定字符串,处理,要求将其分成五个部分,很简单的题目,赛后一遍就对了,不过赛中却忽略了后几个空格的处理,

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 PHONEThe 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.

直接贴代码吧

#include<stdio.h>
#include<string.h>
#include <cmath>
/*char s[150];
char s0[50],s1[50],s2[50],s3[50],s4[50],s11[50];
*/
double stoa(char *str)
{
    int k=0;
    double sum=0;
    int flag=0;
    for(int i=0; i<strlen(str); i++)
    {
        if(str[i]=='.')
        {
            k=i;
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        int j=0;
        for(int i=k-1; i>=0; i--)
        {
            sum+=pow(10.0,j)*(str[i]-'0');
            j++;
        }
        j=-1;
        for(int i=k+1; i<strlen(str); i++)
        {
            sum+=pow(10.0,j)*(str[i]-'0');
            j--;
        }
    }
    else
    {
        int len=strlen(str);
        for(int i=0; i<len; i++)
            sum+=(str[i]-'0')*pow(10.0,len-i-1);
    }
    return sum;
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int cas=1; cas<=t; cas++)
    {
        char s[150]= {0};
        char s0[50]= {0},s1[50]= {0},s2[50]= {0},s3[50]= {0},s4[50]= {0},s11[50]= {0};
        if(cas==1)
            getchar();
        gets(s);
        //printf("%s\n",s);
        int flag=0,k;
        for(int i=0; i<strlen(s); i++)
        {
            if(s[i]=='i'&&s[i+1]=='n'&&s[i+2]=='c'&&s[i+3]=='h'&&s[i+4]=='e'&&s[i+5]=='s'&&s[i-1]==' '&&s[i+6]==' ')
            {
                flag=1;
                k=0;
                int jj=i-1;
                int sum1=0;
                for(int j=jj;j>=0;j--)
                {
                    if(s[j]==' ')
                    {
                        jj--;
                        sum1++;
                    }
                    else
                    break;
                }
                for(int j=jj;j>=0;j--)
                {
                    if(s[j]!=' ')
                    s1[k++]=s[j];
                    else
                    break;
                }
                k=0;
                for(int j=strlen(s1)-1;j>=0;j--)
                s11[k++]=s1[j];
                k=0;
                jj=i-sum1-strlen(s1)-1;
                for(int j=jj;j>=0;j--)
                {
                    if(s[j]==' ')
                    {
                        jj--;
                        sum1++;
                    }
                    else
                    break;
                }
                for(int j=0;j<=jj;j++)
                s0[k++]=s[j];
                k=0;sum1=0,jj=i+6;
                for(int j=jj;j<strlen(s);j++)
                {
                    if(s[j]==' ')
                    {
                        sum1++;
                    }
                    else
                    break;
                }
                for(int j=i+5+sum1+1;j<strlen(s);j++)
                {
                    if(s[j]!='*')
                    s2[k++]=s[j];
                    else
                    break;
                }
                k=0;
                for(int j=i+5+sum1+strlen(s2)+2;j<strlen(s);j++)
                {
                    if(s[j]!=' ')
                    s3[k++]=s[j];
                    else
                    break;
                }
                k=0;
                for(int j=i+5+sum1+strlen(s2)+1+strlen(s3)+1;j<strlen(s);j++)
                {
                    if(s[j]==' ')
                    {
                        sum1++;
                    }
                    else
                    break;
                }
                k=0;
                for(int j=i+5+sum1+strlen(s2)+1+strlen(s3)+1;j<strlen(s);j++)
                {
                    if(s[j]>='A'&&s[j]<='Z')
                    s4[k++]=s[j]+32;
                    else
                    s4[k++]=s[j];
                }
            }
            if(flag==1)
                break;
        }
        double a=stoa(s11);
        double b=stoa(s2);
        double c=stoa(s3);
       //printf("%lf %lf %lf\n",a,b,c);
        //printf("%s/%s/%s/%s/%s\n",s0,s11,s2,s3,s4);
        double sum=sqrt(b*b+c*c)/a;
        if(a==0)
        {
            printf("Case %d: The %s of %s's PPI is 0.00.\n",cas,s4,s0);
        }
        else
        printf("Case %d: The %s of %s's PPI is %.2lf.\n",cas,s4,s0,sum);
    }
    return 0;
}
/*
3
iPhone 4S .00 inches 0960*00640 PHONE
The new iPad        .5 inches 2048*1536 PAD
ddinches  3.5 inches 960*640 PHONE
*/


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值