题目网址:http://acm.fzu.edu.cn/problem.php?pid=2193

Problem Description

请将有限小数化为最简分数。

Input

一个整数n 表示需要转化的小数个数;接下来n行,每行有一个有限小数。(保证小数位数不超过9位)

Output

输出有n行,每行为小数对应的最简分数

Sample Input

20.50.4

Sample Output

1/22/5

Hint

注意精度问题,数据保证不会有类似1.0的小数。

Source

福州大学第十二届程序设计竞赛

考虑集中特殊情况即可。

#include<iostream>
#include<algorithm>
#include <cstdio>
#define INF 0x3f3f3f3f;
using namespace std;
int gcd(int a,int b){
if(b==0) return a;
int t=a%b;
while(t!=0){
a=b;
b=t;
t=a%b;
}
return b;
}
int pow(int x){
int n=1;
for(int i=0;i<x;i++){
n*=10;
}
return n;
}
int main (){
int T;
cin>>T;
while(T--){
string str;
cin>>str;
int len=str.length();
int mark=0,n=0,pot;
for(int i=0;i<len;i++){
if( (mark==0&&str[i]=='0') )
continue;
if( str[i]=='.')
pot=i;
else{
n=n*10+str[i]-'0';
mark=1;
}
}
int y=pow(len-pot-1);
int gg=gcd(n,y);
//cout<<gg<<' '<<n<<'/'<<y<<endl;
n=n/gg,y=y/gg;
if(n==y)
cout<<1<<endl;
else if(y==1) cout<<n<<endl;
else
cout<<n<<'/'<<y<<endl;
}
return 0;
}

So Hard (水题)的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  3. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  4. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  5. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  6. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

  7. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  8. ACM水题

    ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...

  9. CF451C Predict Outcome of the Game 水题

    Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...

  10. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

随机推荐

  1. maven学习笔记(定制普通Java一个项目)

    创建一个新项目: mvn archetype:generate -DgroupId=cn.net.comsys.ut4.simpleweather -DartifactId=simple-weathe ...

  2. 功能更强大的格式化工具类 FormatUtils.java

    package com.util; import java.text.DecimalFormat; import java.text.ParseException; import java.text. ...

  3. spring 中事务的PROPAGATION_REQUIRED,Readonly的解释

                 一.事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为, 它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播 ...

  4. 在web.config里面添加配置信息

    在web.config里面添加配置信息规范文字 代码如下 在<appSettings>中间添加 <add key="Director" value="处 ...

  5. 【jmeter】元件的作用域与执行顺序

    1.元件的作用域 JMeter中共有8类可被执行的元件(测试计划与线程组不属于元件),这些元件中,取样器是典型的不与其它元件发生交互作用的元件,逻辑控制器只对其子节点的取样器有效,而其它元件(conf ...

  6. 【转】linux-系统启动流程详解

    第二十章.启动流程.模块管理与 Loader 最近升级日期:2009/09/14 1. Linux 的启动流程分析 1.1 启动流程一览 1.2 BIOS, boot loader 与 kernel ...

  7. 求助:为什么我用360浏览器和UC浏览器打不开JAVA中的index.html文件? 一打开就显示浏览器首界页

    如下图,在oracle官网下载了一个JAVA的API文档,双击index.html时打开是浏览器的首页,不知道为什么?请问怎样才能以chm文档格式显示?

  8. Chrome插件开发入门(二)——消息传递机制

    Chrome插件开发入门(二)——消息传递机制   由于插件的js运行环境有区别,所以消息传递机制是一个重要内容.阅读了很多博文,大家已经说得很清楚了,直接转一篇@姬小光 的博文,总结的挺好.后面附一 ...

  9. Spark1.4启动spark-shell时initializing失败

    错误信息如下: 5/11/03 16:48:15 INFO spark.SparkContext: Running Spark version 1.4.1 15/11/03 16:48:15 WARN ...

  10. DBA_Oracle Erp R12安装虚拟机镜像IP修正(案例)

    2014-07-12 Created By BaoXinjian