zoukankan      html  css  js  c++  java
  • Gym 100733C

    题目:

      

    Even though he is the head of the Shitalian Mafia, Shi doesn't like bloodshed and punishes his subordinates if they kill innocent people. That is why the death report is always written in the following way: "We killed x% of the innocent people".

    Shi wants to know the smallest number of innocent people that must have been in that place so that exactlyx% of the innocent people have died.

    For instance, if we have x = 35%. In this case we had 20 people, and 7 were victims, because 35% of 20 is 7. That is the minimum possible.

    Input

    There is a single number 0 ≤ x ≤ 100 with at most 15 decimal places.

    Output

    Print the number sought by Shi.

    Sample Input

    Input
    35
    Output
    20
    Input
    50.0
    Output
    2
    Input
    7.500
    Output
    40
    Input
    35.123456789
    Output
    100000000000
    题意:
    给你一个百分数,让你求一个最小数,使得这个最小的整数乘以这个百分数后可以得到一个整数
    分析:
    把给定的数存为字符串,使得可以计算出移动小数点多少位后(k),可以使的给的实数变为整数,然后分子分母通扩大k倍,然后乱搞。。。。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 using namespace std;
     6 typedef long long LL;
     7 char num[20];
     8 LL a[20];
     9 LL gcd(LL a,LL b)
    10 {
    11     return b==0? a:gcd(b,a%b);
    12 }
    13 int main()
    14 {
    15     scanf("%s",num);
    16     int n=strlen(num);
    17     //printf("n==%d\n",n);
    18     int k=0;
    19     for(int i=0;i<n;i++)
    20     {
    21         if(num[i]=='.')
    22         {
    23             k=n-i-1;
    24             break;
    25         }
    26     }
    27     //printf("%d\n",k);
    28     LL cnt=0;
    29     for(int i=0;i<n;i++)
    30     {
    31         if(num[i]=='.') continue;
    32         else
    33         cnt=cnt*10+(num[i]-'0');
    34         //printf("cnt==%lld\n",cnt);
    35     }
    36     //printf("%lld\n",cnt);
    37     LL m=100;
    38     for(int i=1;i<=k;i++)
    39     {
    40         m=m*10;
    41     }
    42     //printf("m=%lld\n",m);
    43     LL ans=gcd(cnt,m);
    44     //printf("%lld\n",ans);
    45     printf("%lld\n",m/ans);
    46     return 0;
    47 }
  • 相关阅读:
    Classification and Representation(分类与表示)
    静态链表
    拓扑序列
    二分图问题
    大数据概述
    QT出现应用程序无法正常启动0xc000007b的错误
    简易有穷自动机实验
    一个简易的C语言文法
    词法分析器实验报告
    浅谈词法分析器
  • 原文地址:https://www.cnblogs.com/forwin/p/4807001.html
Copyright © 2011-2022 走看看