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 ...
随机推荐
- JS触发事件大全
事件 浏览器支持 解说 一般事件 onclick IE3.N2 鼠标点击时触发此事件 ondblclick IE4.N4 鼠标双击时触发此事件 onmousedown IE4.N4 按下鼠 ...
- The file couldn’t be opened because you don’t have permission to view it
because you dont have permission to view it 解决办法 Project---Build Setting中 修改这一项,变成Default Compiler(A ...
- 【转载】一致性hash算法释义
http://www.cnblogs.com/haippy/archive/2011/12/10/2282943.html 一致性Hash算法背景 一致性哈希算法在1997年由麻省理工学院的Karge ...
- 仿51job.com城市选择框特效
650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...
- GDB中应该知道的几个调试方法 来自陈皓
GDB中应该知道的几个调试方法 2011年2月10日陈皓发表评论阅读评论62,325 人阅读 七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询 ...
- MD5 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)
MD5 编辑 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护.该算法的文件号为RFC 1321( ...
- (JS高手不用看了!我只是在碎碎念,因为我也不知道面什么)JavaScript的算术运算
Math.pow(2,53) //2的51次幂 Math.round(0.6) //四舍五入 Math.cell(0.6) //向上求整 Math.floor(0.6) / ...
- ExtJS学习之路第三步:理解引擎之下,ExtJS4中的类
写写就发现,有些代码不查查源头,不明白是怎么回事?搜到这篇文章觉得还是收益匪浅,更容易读懂代码. Classes in Ext JS 4: Under the hood Countdown to Ex ...
- HDOJ 2389 Rain on your Parade
HK.... Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K ...
- editplus快捷键大全之editplus编辑快捷键
前面我们说了editplus快捷键大全之editplus文件快捷键和editplus快捷键大全之editplus光标快捷键,这里我们讲一下editplus快捷键大全之editplus编辑快捷键 删除光 ...