字符串处理sdut 2411
题目:http://www.sdutacm.org/sdutoj/problem.php?action=showproblem&problemid=2411
关于字符串处理的题,此题坑点很多wr了好多便,但是学到了很多的用法:
字符串有空格的输入输出,sscanf的用法等等;
还有一个浮点数精度的问题我也学到了,一个浮点型的数小于eps(1e-9)便视为零,还有sqrt函数要的精度问题
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#define eps 1e-9
using namespace std;
int main()
{
char ch;
int c=,i,t,j,n,k;
char str[][];
scanf("%d",&t);
while(t--)
{
ch='/0';
n=;
double sum1,sum2,ans,dp;
while(ch!='\n')
{
scanf("%s%c",str[n],&ch);
if(strcmp(str[n],"inches")==NULL)
k=n;
n++;
}
sscanf(str[k-],"%lf",&ans);
sscanf(str[k+],"%lf*%lf",&sum1,&sum2);把字符串
j=k+;
while(j<n)
{
int sign=strlen(str[j]);
for(i=; i<sign; i++)
{
if(str[j][i]<='Z'&&str[j][i]>='A')
str[j][i]+=;
}
j++;
}
dp=*sqrt(sum1*sum1/+sum2*sum2/);提高精度
if(ans<eps)
{
printf("Case %d: The",c++);
i=k+;
while(i < n)
{
printf(" %s", str[i]);
i++;
}
printf(" of");
for(i=; i<k-; i++)
{
printf(" %s",str[i]);
}
ans=;
printf("'s PPI is %.2lf.\n",ans);
}
else
{
printf("Case %d: The",c++);
i=k+;
while(i < n)
{
printf(" %s", str[i]);
i++;
}
printf(" of");
for(i=; i<k-; i++)
{
printf(" %s",str[i]);
}
printf("'s PPI is %.2lf.\n",dp/ans);
}
}
return ;
}
字符串处理sdut 2411的更多相关文章
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
Pixel density Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Pixels per inch (PPI) or pi ...
- 串结构练习——字符串连接(SDUT 2124)
Problem Description 给定两个字符串string1和string2,将字符串string2连接在string1的后面,并将连接后的字符串输出. 连接后字符串长度不超过110. Inp ...
- SDUT 2411:Pixel density
Pixel density Time Limit: 1000MS Memory limit: 65536K 题目描述 Pixels per inch (PPI) or pixel density is ...
- sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)
n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you w ...
- SDUT OJ 2892 A (字典树问题-输出出现次数最多的字符串的出现次数,60ms卡时间,指针+最后运行完释放内存)
A Time Limit: 60ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 给出n(1<= n && n <= 2*10^6)个字 ...
- SDUT 3035 你猜我猜不猜你猜不猜(字符串 规律性)
你猜我猜不猜你猜不猜 Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In the past 39th annual ACM in ...
- SDUT OJ 之 1571 《人品,有没有?》 字符串的处理问题
人品,有木有? Time Limit: 1000ms Memory limit: 32768K 有疑问?点这里^_^ 题目描述 新一届的山东理工大学ACM网络擂台赛就要开始啦!听说晋级的选手有机 ...
- sdut 2125串结构练习--字符串匹配【两种KMP算法】
串结构练习——字符串匹配 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目链接:http://acm.sdut.edu.cn/sduto ...
- sdut 487-3279【哈希查找,sscanf ,map】
487-3279 Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接: sdut: http://acm.sdut.ed ...
随机推荐
- Dictionary——通过value找Key
Dictionary<string, string> dic = GetRoleDescriptions(); string key = dic.FirstOrDefault(x => ...
- 作为一名合格的JAVA程序员需要点亮那些技能树?
以下是出现次数超过100的一些技能,大家可以做一个参考. Spring 299 MySQL 290 JavaScript 216Linux 165J2EE 151设计模式 148Struts2 138 ...
- 一篇搞定spring Jpa操作数据库
开始之前你必须在项目配置好数据库,本文使用的spring boot,相比spring,spring boot省去了很多各种对以来组件复杂的配置,直接在pom配置组件,完后会自动帮我们导入组件 < ...
- python的标准类型分类
数据属性 储存模型 更新模型 访问模型 数字 标量/原子类型 不可变类型 直接存取 字符串 标量/原子类型 不可变类型 顺序 列表 容器 可变类型 顺序 元组 容器 不可变类型 顺序 字典 容器 ...
- 017-Hadoop Hive sql语法详解7-去重排序、数据倾斜
一.数据去重排序 1.1.去重 distinct与group by 尽量避免使用distinct进行排重,特别是大表操作,用group by代替 -- 不建议 select DISTINCT key ...
- microsoft cl.exe 编译器
cl.exe是visual stdio 内置的编译器,visual stdio包含各种功能,有些功能可能这辈子都用不到,体积庞大,如果是 开发比较大或者有图形的项目,vs是首选.更多情况时更喜欢使用文 ...
- numpy的通用函数:快速的元素级数组函数
通用函数(ufunc)是对ndarray中的数据执行元素级运算的函数.可看作简单函数的矢量化包装. 一元ufunc sqrt对数组中的所有元素开平方 exp对数组中的所有元素求指数 In [93]: ...
- RedisClient For .Net
Redis Client For .Net 介绍 redis支持各种语言版本的client,其中.net平台下比较火的有ServiceStack.Redis和StackExchange.Redis 选 ...
- 算法题14 小Q歌单,牛客网,腾讯笔试题
算法题14 小Q歌单,牛客网,腾讯笔试题 题目: 小Q有X首长度为A的不同的歌和Y首长度为B的不同的歌,现在小Q想用这些歌组成一个总长度正好为K的歌单,每首歌最多只能在歌单中出现一次,在不考虑歌单内歌 ...
- 面向对象高级编程——使用@property
在绑定属性的时候,如过我们直接把属性暴露出去,虽然写起来简单,但是,没办法检查参数,导致可以把成绩随意改: s = Student() s.score = 9999 #不符合常规依然可以更改 这显然不 ...