sdut 2411: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).
示例输入
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.
提示
Wp is width resolution in pixels, Hp is height resolution in pixels.
来源
1、inches尺寸前面的数可以是整数,也可以是浮点数,也就是说可能有小数点,也可能没有。所以不能用小数点'.'作为标记。
2、空格问题。字符串前面可能有空格,每个单词中间可能有多个空格,最后也可能有多个空格。
3、注意尺寸和高*宽两个数字部分,可能写错。也就是说有这几种情况:0.0,0,00000,0009.2,9.20000,0640*480000。
4、注意类型kind提取出来后要全部转换成小写字母。
5、输出的时候不要漏掉最后的句号。
#include <iostream>
#include <string.h>
#include <cmath>
#include <stdio.h>
using namespace std;
char str[];
double Abs(double n)
{
return n<?-n:n;
}
void GetVal(char name[],char kind[],double &ppi)
{
//iPhone 4S 3.5 inches 960*640 PHONE
int len = strlen(str),indexl,indexr,i,t,x;
double a,b,c;
//类型后界
for(indexr=len-;indexr>=;indexr--)
if(str[indexr]!=' ')
break;
//类型前界
for(indexl=indexr;indexl>=;indexl--)
if(str[indexl]==' ')
break;
//提取类型
t = ;
for(i=indexl+;i<=indexr;i++){
if('A'<=str[i] && str[i]<='Z') //类型的大写全部转换成小写
kind[t++] = str[i] + ;
else
kind[t++] = str[i];
}
kind[t] = '\0';
//a*b的b的后界
for(indexr = indexl;indexr>=;indexr--)
if(str[indexr]!=' ')
break;
//提取b
t = ;x = ;
for(i=indexr;str[i]!='*';i--){
int tt = str[i]-'';
t = tt*x + t;
x*=;
}
b = t;
//提取a
indexr = i-;
t = ;x = ;
for(i=indexr;str[i]!=' ';i--){
int tt = str[i]-'';
t = tt*x + t;
x*=;
}
a = t;
for(indexr = i;str[indexr]==' ';indexr--);
for(;str[indexr]!=' ';indexr--);
//找c的下界
for(;str[indexr]==' ';indexr--);
//找c的上界
for(indexl = indexr;str[indexl]!=' ';indexl--);
for(i = indexl+;str[i]!='.' && i<=indexr;i++); //找到小数点或者到下界
if(str[i]=='.'){ //有小数点,证明是小数
//提取c的小数部分
c = ;
double xx = 0.1;
int j;
for(j=i+;str[j]!=' ';j++){
int tt = str[j]-'';
c = c+tt*xx;
xx/=;
}
//提取c的整数部分
x = ;
for(j=i-;str[j]!=' ';j--){
int tt = str[j]-'';
c = c+tt*x;
x*=;
}
indexr = j;
}
else { //不是小数点,证明是整数
//提取整数
c = ;
x = ;
int j;
for(j=indexr;str[j]!=' ';j--){
int tt = str[j]-'';
c = c+tt*x;
x*=;
}
indexr = j;
}
//可以计算ppi了
if( Abs(c)<1e- ) //是0
ppi = ;
else
ppi = sqrt(a*a+b*b)/c;
//名字后界
for(;indexr>=;indexr--)
if(str[indexr]!=' ')
break;
//类型前界
for(indexl=;str[indexl]==' ';indexl++);
//提取名字
t = ;
for(i=indexl;i<=indexr;i++)
name[t++] = str[i];
name[t] = '\0';
}
int main()
{
int T;
cin>>T;
getchar();
for(int cnt = ;cnt<=T;cnt++){
cin.getline(str,,'\n');
char name[],kind[];
double ppi;
GetVal(name,kind,ppi); //提取数据:名字,类型,ppi
printf("Case %d: The %s of %s's PPI is %.2lf.\n",cnt,kind,name,ppi);
}
return ;
}
Freecode : www.cnblogs.com/yym2013
sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)的更多相关文章
- sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
- sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)
n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you w ...
- sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)
Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you a ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)
Crack Mathmen Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take securit ...
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
随机推荐
- 使用NPOI操作Excel(03、07)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.SS. ...
- hdu 2048 神、上帝以及老天爷
经典错排问题,算出n个人的排列可能,即求n!. 在本题中设定所有人即n个人全部拍错,即求n错排. 要求:求出其全部错排发生的概率 n错排 / n! * 100 以小数形式输出即可. #include ...
- hdu 2047 阿牛的EOF牛肉串
如果末尾加的是E或F,显然是2*a[i-1] 如果末尾加的是O,则末2位一定是EO或FO,则为2*a[i-2]. 然后两者相加 2*a[i-1]+2*a[i-2] = 2*(a[i-1]+a[i-2] ...
- C# 设置开机自动启动(注册表方式)
.NET技术交流群 199281001 .欢迎加入. using System; using System.Collections.Generic; using System.Linq; using ...
- SVM算法入门
转自:http://blog.csdn.net/yangliuy/article/details/7316496SVM入门(一)至(三)Refresh 按:之前的文章重新汇编一下,修改了一些错误和不当 ...
- linux下搭建Nginx
Linux上搭建nginx,及简单配置 在上家公司都是运维安装nginx,到新公司后代码开发完成部署测试服务器要求自己装nginx,研究了好久安装好之后,到正式上线还要自己安装,索性把安装步骤自己记 ...
- 将DataSet(DataTable)转换成JSON格式(生成JS文件存储)
public static string CreateJsonParameters(DataTable dt) { /**/ /**/ /**/ /* /*********************** ...
- 5 个最受人喜爱的开源 Django 包
导读 Django 围绕“可重用应用”的思想建立:自包含的包提供了可重复使用的特性.你可以将这些可重用应用组装起来,在加上适用于你的网站的特定代码,来搭建你自己的网站.Django 具有一个丰富多样的 ...
- NGUI之UICamera控制触摸,鼠标事件
http://blog.csdn.net/onerain88/article/details/18963539 . UICamera 功能介绍 主要包括UI事件的监听,分发,覆盖范围为此Camera渲 ...
- xcode Git
http://blog.csdn.net/w13770269691/article/details/38704941 在已有的git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中, ...