Rational Ratio (2018 ACM-ICPC North Central North America Regional Contest)

滴答滴答---题目链接 

Every (positive) rational number can be expressed as a ratio of two (positive) integers. However, in decimal form, rational numbers often have an infinitely repeating pattern, e.g., 1/7=0.1428571428571428571/7=0.142857142857142857... A convenient way of writing this repeating pattern is to put a bar over the first occurrence of the repeating part, so 1/71/7 would be written:

0.142857⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯.0.142857¯.

Given a rational number consisting of a series of digits, followed by a decimal point, followed by more digits, and then a number indicating how many of the rightmost digits repeat (i.e., the number of digits under the bar), your task is to find the ratio of two integers, in the most reduced form, that represent the same rational number. For example, for the input “0.1428570.142857 66” you should find 1/71/7.

Input

The input will be a single line with two numbers separated by one space. The first number will consist of 11 to 33 digits (00–99), followed by a decimal point, followed by 11 to 1111 digits (00–99), representing the decimal form of the number, possibly with leading zeros. The second number will be a positive integer indicating how many of the rightmost digits of the preceding number repeat. The first number will always be greater than 00. The second number will never be less than 11 nor larger than the number of digits to the right of the decimal point.

Output

Print the corresponding fraction in its most reduced form, that is, the fraction with the smallest possible integer values in the numerator and denominator.

Sample Input 1Sample Output 1
0.142857 6
1/7
Sample Input 2Sample Output 2
1.6 1
5/3
Sample Input 3Sample Output 3
123.456 2
61111/495

      题意:把给出的循环小数,转换为分数

     

//#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    char ch;
    string s;
    ll fm=1,fz=0,tt;
    int k;
    cin>>tt>>ch>>s>>k;
    int len=s.size();
    for(int i=len-k; i<len; i++)
    {
        fz=fz*10+s[i]-'0';
    }
    for(int i=0; i<k; i++)
        fm*=10;
    fm--;
    ll tf=1;
    for(int i=0; i<len-k; i++)
    {
        fm*=10;
        tf*=10;
        tt=tt*10+s[i]-'0';
    }
    ll ffm=tf*fm;
    ll ffz=tt*fm+fz*tf;
    ll ans=__gcd(ffz,ffm);
    ffz/=ans;
    ffm/=ans;
    cout<<ffz<<"/"<<ffm<<endl;
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Rational Rose可以通过以下步骤来绘制E-R图: 1. 打开Rational Rose软件,创建一个新的数据建模项目。 2. 在“模型浏览器”中,右键单击“类图”,选择“新建类图”。 3. 在“工具箱”中,选择“E-R图”工具。 4. 在类图中,单击“E-R图”工具,然后单击类图中的任何位置,将创建一个新的E-R图。 5. 在E-R图中,使用“实体”工具创建实体。 6. 使用“属性”工具为每个实体添加属性。 7. 使用“关系”工具创建实体之间的关系。 8. 使用“角色”工具为每个关系添加角色。 9. 使用“基数”工具为每个角色指定基数。 10. 使用“约束”工具为每个关系添加约束。 11. 在完成E-R图后,保存并关闭Rational Rose软件。 以上是绘制E-R图的基本步骤,具体操作可以根据实际情况进行调整。 ### 回答2: Rational Rose是一个常用的软件工程工具,它可以帮助开发人员进行软件设计、建模和测试。其中,E-R图是一种数据建模技术,用于描述实体、属性和关系之间的关系。下面是关于如何在Rational Rose中画E-R图的步骤: 1. 打开Rational Rose软件,在主界面上选择“New”->“Class Diagram”创建一个类图。 2. 在画图工具栏中,选择实体类图符号,可以通过点击或拖拽的方式将实体类符号拖入画布中。 3. 在每个实体类中加入属性,可以通过右键单击实体类,并选择“Attribute”选项,输入属性名称和数据类型。 4. 添加关系: 在画图工具栏中选择关系符号,在实体类中选择要建立关系的实体类,然后可以建立关系。 5. 在建立关系时,可以选择画直线关系/菱形关系,具体来说,菱形关系表示关系的模糊性或非确定性,而实线关系表示关系的明确性和确定性。 6. 继续建立关系后,可以进行连接线的美化操作:如设置线条宽度、颜色、箭头/菱形等。 7. 为了使E-R图更加清晰,可以给属性以及关系添加文本标签。 总体来说,在使用Rational Rose画E-R图时,需要先明确实体类、属性和关系等概念,然后选择合适的工具符号并合理地建立实体类之间的关系,最后进行美化和调整。这样可以使得E-R图更加准确、简洁。 ### 回答3: Rational Rose是一款功能强大的UML建模工具,其中包括E-R图建模。下面我们将介绍如何使用Rational Rose画E-R图。 第一步,打开Rational Rose软件,并创建一个新的UML项目。选择菜单栏中的“File”选项,点击“New”来创建新的项目。 第二步,创建一个新的类别。选择“Model Explorer”,然后选择“Class”图标。在新建的类别中,选择“Entities”和“Associations”来自定义E-R图。 第三步,选择“Entity”图标来添加实体。点击所选择的类别,然后在右侧的“Properties”面板中输入实体的名称。 第四步,在实体中添加属性。在实体上右键单击,并选择“Add Attribute”来添加属性。在右侧的“Properties”面板中输入属性的名称和数据类型。 第五步,定义关系。在“Associations”小节中选择“Association”图标,并拖动它到实体之间创建连接。选择连接,在右侧面板“Properties”中定义关系类型、角色名称、代理关系等信息。 第六步,完成E-R图。添加实体和关系,创建整个图象。这样可以创建完整的E-R图。 总之,使用Rational Rose画E-R图需要仔细考虑每个实体和各个组合之感关系,细节决定了总体的有效性。画好E-R图可以使数据模型设计更加正确,方便数据库建立和开发。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值