zoukankan      html  css  js  c++  java
  • CF 900B

    CF 900B
        Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
     

    Description

    现有一式子 a / b. 你需要找出数字 c 在小数点后第一次出现的位置

    Input

    输入包含三个整数 a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).

    Output

    输出数字 c 第一次在小数点后出现的位置,如果 c 不在小数点后出现输出 -1

    Sample Input

    Input
    1 2 0
    
    Output
    2
    
    Input
    2 3 7
    
    Output
    -1

    Hint

    第一组样例 : 1 / 2 = 0.5000(0) 出现在第二个位置

    第二组样例 : 2 / 3 = 0.6666(6) 7 没有出现,输出 -1

    本题主要有两个易错点,一是不要认为只寻找小数点后六位,我是开到了小数点后1000位。二是double的精度问题,因为double存储格式的问题,存储的小数是不精确的,所以避免小数的运算,转为整数的运算。

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<deque>
    #include<iostream>
    using namespace std;
    const int INF=0x3f3f3f3f;
    const int N=200;
    int main()
    {
        int i,p,j;
        int a,b,c,flag=0;
        scanf("%d%d%d",&a,&b,&c);
        for(i=0; i<=10000; i++)
        {
            if(a<b&&flag==0)
                flag=i+1;
            if(a<b)
            {
                a*=10;
                p=a/b;
                if(p==c&&flag!=0)
                    break;
                a=a%b;
            }
            else
            {
                a=a%b;
            }
    
        }
        if(i<=1000)
            printf("%d
    ",i+2-flag);
        else
            printf("-1
    ");
        return 0;
    }
  • 相关阅读:
    java8之OptionalDemo
    Java8之日期和时间demo
    bitUtils
    在线工具类网站
    linux配置nginx命令
    批处理命令:修改IP与DNS地址脚本
    Springboot解决使用@Scheduled创建任务时无法在同一时间执行多个任务的BUG
    Selenium常用命令
    火狐浏览器各版本下载地址
    Mysql安装多版本数据库
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9323246.html
Copyright © 2011-2022 走看看