山东省第三届ACM省赛Pixel density

#include <iostream>  
#include <stdio.h>  
#include <cstring>  
#include <cmath>  
  
using namespace std;  
  
char str[1000][1000];  
char type[1000];  
  
//本题目使用scanf巧妙分段,将不同数据保存在不同的数组中,受教了。  
void ace()  
{  
    int t, i, j;  
    scanf("%d", &t);  
    int no, apart, n;  
    double inches, wp, hp, dp, ppi;  
    char ch;  
    for(no = 1; no <= t; no++)  
    {  
        n = 0;  
        ch = '\0';  
        while(ch != '\n')  
        {  
            scanf("%s%c", str[n], &ch);  
            if(!strcmp(str[n], "inches"))//记录inches的位置  
                apart = n;  
            n++; //n为串数  
        }  
        sscanf(str[apart-1],"%lf", &inches);  
        sscanf(str[apart+1],"%lf*%lf", &wp, &hp);  
  
        //output type  
        i = apart + 2;  
        while(i <= n)  
        {  
            for(j = 0; str[i][j] != '\0'; j++)  
            {  
                if(str[i][j] >= 'A' && str[i][j] <= 'Z')  
                    str[i][j] = str[i][j] + 'a' - 'A';  
            }  
            i++;  
        }  
        i = apart + 2;  
        printf("Case %d: The %s ", no, str[i]);  
        i++;  
        while(i < n)  
        {  
            printf("%s ", str[i]);  
            i++;  
        }  
        printf("of ");  
  
        //output name  
        for(i = 0; i <= apart - 2; i++)  
        {  
            if(i != apart - 2)  
                printf("%s ", str[i]);  
            else  
                printf("%s", str[i]);  
        }  
        //防止超精度  
        dp = 10 * sqrt(wp * wp / 100 + hp * hp / 100 );  
        if(inches <= 1e-9)  
            ppi = 0;  
        else  
            ppi = dp / inches;  
  
        printf("'s PPI is %.2lf.\n", ppi);  
        //printf case  
    }  
}  
  
  
int main()  
{  
    ace();  
    return 0;  
}  

/***************************************************
User name: 但求心安
Result: Accepted
Take time: 0ms
Take Memory: 216KB
Submit time: 2017-05-02 20:25:51
****************************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值