sdut 2411 Pixel density
2013-06-06 00:13
260 查看
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.
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n,t,i,j,k,pos,lenth; double p,wp,hp,ans; char s[101][101],c; scanf("%d",&n); for(t = 1; t <= n; t++) { for(i = 0; ; i++) { scanf("%s",s[i]); c = getchar();没有想到输入字符,判断是否该字符串结束 if(c == '\n') { lenth = i; break; } } for(j = 0; j <= i; j++) { if(strcmp(s[j],"inches") == 0) { sscanf(s[j-1],"%lf",&p); sscanf(s[j+1],"%lf*%lf",&wp,&hp); pos = j-1; break; } } for(i = pos + 3; i <= lenth; i++) for(k = 0; s[i][k] ; k++) { if(s[i][k] >= 'A' && s[i][k] <= 'Z') s[i][k] = s[i][k] +32; } ans = sqrt(wp*wp+hp*hp); printf("Case %d: The",t); for(i = pos +3; i <= lenth; i++) printf(" %s",s[i]); printf(" of"); for(i = 0; i < pos-1; i++) printf(" %s",s[i]); printf(" %s's",s[pos-1]); printf(" PPI is %.2lf.\n",fabs(p-0)<=1e-9?0.00:ans/p); } return 0; }
把每个长的字符串分成若干个小字符串放在二维数组中,找到"inches"所在位置,再将它左右的数字取出来计算。。。悲催啊,将字符串输错了,一直wa.以后还是复制粘贴吧。
相关文章推荐
- SDUT 2411 Pixel density(模拟,字符串)
- Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)
- sdut2411 Pixel density
- 【模拟细节毕业题】SDUT 2411——Pixel density
- SDUT 2411——Pixel density模拟细节WA了n遍
- Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
- SDUT:2411 Pixel density
- SDUT 2411:Pixel density
- SDUT ACM 2411 Pixel density 字符串处理
- Pixel density sdut2411 ACM算法设计
- SDUT-3379 数据结构实验之查找七:线性之哈希表
- sdut1696
- SDUT 趣味循环赛第二场 玄黄的三角形题解
- 【运算符重载】SDUT 1272-面向对象程序设计上机练习十(运算符重载)
- SDUT 2018 Winter Individual Contest - 3
- SDUT 3358 (动态规划) 高数Umaru系列(9)——哈士奇
- SDUT 2122 数据结构实验之链表七:单链表中重复元素的删除
- SDUT 3334 数据结构实验之栈与队列七:出栈序列判定
- SDUT_汶川地震买米_贪心