SDUT 2411 Pixel density (山东省第三届省赛) 模拟

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2411

首先要找到输入与输出的规律。。。

我们仔细观察题目的话,可以发现 他给我们的格式是 “名称 + 屏幕大小(以英寸为单位)+ inches + 屏幕规格(Wp*Hp) +  类型”。其中加号的位置可以有若干个空格,当然在名称和类型中也可以有若干个空格。最后输出的时候,字符串之间只能有一个空格,类型必须转化为小写,最后一行不能有换行符。还有一个坑,就是当Inches为0的情况,这是你就要另外处理。
输出的格式是“The + 类型 + of + 名称's + PPI is + 像素.”。

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1010;
char s[101][101];  //存储原字符
char name[maxn],type[maxn];
void change(char *p)   //将类型转换为小写字母
{
    int len = strlen(p);
    for(int i=0;i<len;i++)
    {
        if(p[i]>='A' && p[i]<='Z')
            p[i] += 32;
    }
}
double DP(double inches,double wp,double hp)
{
    return sqrt(wp*wp+hp*hp)/inches;
}
int main()
{
    int n;
    double a,wp,hp,ans;
    int cnt;
    int k;
    scanf("%d",&n);
    getchar();
    for(int t=1;t<=n;t++)
    {
        cnt = 0;
        memset(name,0,sizeof(name));
        memset(type,0,sizeof(type));
        while(scanf("%s",s[cnt]))
        {
            if(strstr(s[cnt],"inches")!=NULL)  //找到最后一个inches
                k = cnt;
            cnt ++;
            if(getchar()=='\n')
                break;
        }
        sscanf(s[k-1],"%lf",&a);
        sscanf(s[k+1],"%lf*%lf",&wp,&hp);
        for(int i=0;i<k-1;i++)
        {
            if(i)
                strcat(name," ");
            strcat(name,s[i]);
        }
        for(int i=k+2;i<cnt;i++)
        {
            strcat(type,s[i]);
            if(i!=cnt-1)
                strcat(type," ");
        }
        change(type);
        if(a==0.0)
            ans = 0;
        else
            ans = DP(a,wp,hp);
        printf("Case %d: The %s of %s's PPI is %.2lf.\n",t,type,name,ans);
    }
    return 0;
}

参考博客:https://blog.csdn.net/luomingjun12315/article/details/45419083

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值