第三届山东ACM省赛回顾 Pixel density (字符串处理)
2015-04-30 21:12
399 查看
Pixel density
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2411Time 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 photographsusually 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 inchesor 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 definethe 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. 329.65 = (960*960+640*640)/3.5; 题意不难理解,直接上代码吧:#include <stdio.h> #include <cstring> #include <stdlib.h> #include <cmath> #include <ctype.h> int main() { int n; scanf("%d",&n); getchar(); int cas=0; char s[10000]; while(n--) { memset(s,'\0',sizeof(s)); cas++; gets(s); int len=strlen(s); char sname[2000]; char slen[2000]; char shp[2000]; char swp[2000]; char stype[2000]; memset(sname,'\0',sizeof(sname)); memset(slen,'\0',sizeof(slen)); memset(shp,'\0',sizeof(shp)); memset(swp,'\0',sizeof(swp)); memset(stype,'\0',sizeof(stype)); double dia; long long wp,hp; int sign=0; for(int i=0;i<len;i++) { if(s[i]==' '&&s[i+1]==' ') { sign=i+2; break; } sname[i]=s[i]; } int k=0; for(int i=sign;i<len;i++) { if(s[i]==' ') { sign=(i+8); break; } slen[k++]=s[i]; } dia=atof(slen); k=0; for(int i=sign;i<len;i++) { if(s[i]=='*') { sign=(i+1); break; } shp[k++]=s[i]; } hp=atoi(shp); k=0; for(int i=sign;i<len;i++) { if(s[i]==' ') { sign=i+1; break; } swp[k++]=s[i]; } wp=atoi(swp); k=0; while(s[sign]==' ') //一直PE,后台数据有问题,巨坑。。。 (题目没说输出格式,让我们照着样例去猜,,可是) sign++; //2 // iPhone 4S 3.5 inches 960*640 PHONE <-这个PHONE前面明明只有一个空格,,但是后台数据允许有多个,所以加了个while循环就过了 //The new iPad 0009.7 inches 2048*1536 PAD for(int i=sign;i<len;i++) { stype[k++]=tolower(s[i]); } double ans; if(fabs(dia)<=1e-7) ans=0; else ans=sqrt(wp*wp+hp*hp+0.0)/dia; printf("Case %d: The %s of %s\'s PPI is %.2lf.\n",cas,stype,sname,ans); } return 0; }
相关文章推荐
- 第三届山东ACM省赛回顾 Pixel density (字符串处理)
- Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)
- Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
- SDUT ACM 2411 Pixel density 字符串处理
- C语言回顾(四、字符串及其处理函数重写)——iOS开发基础
- sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)
- 回顾一下各种字符串处理函数
- Pixel density(简单的字符串处理)
- Win32中的字符串处理
- Lua字符串中的中英文分割处理
- L脚本语言字符串处理
- php中的字符串处理函数总结
- java 字符串分离处理技术
- C#字符串转换为日期时间格式及其错误处理
- 字符串分拆并统计的处理示例.sql
- NSString / NSMutableString 字符串处理,常用代码 (实例)
- WinHack的开发技术经验(1)-使用 Unicode 作为内部字符串处理
- 字条与字符串处理
- hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)