zoukankan      html  css  js  c++  java
  • hdoj--2522--A simple problem(数学模拟)

    A simple problem

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 3866    Accepted Submission(s): 1444


    Problem Description
    Zty很痴迷数学问题.。一天,yifenfei出了个数学题想难倒他,让他回答1 / n。但Zty却回答不了^_^. 请大家编程帮助他.
     

    Input
    第一行整数T,表示测试组数。后面T行,每行一个整数 n (1<=|n|<=10^5).
     

    Output
    输出1/n. (是循环小数的,只输出第一个循环节).
     

    Sample Input
    4 2 3 7 168
     

    Sample Output
    0.5 0.3 0.142857 0.005952380
     

    Author
    yifenfei
     

    Source
     

    Recommend
    gaojie   |   We have carefully selected several similar problems for you:  1496 1280 1264 2600 2523


    /*其实这一道题跟一般的数学除法很像,只是真正的小数除法都是在小数点后边,
    但是那样在c语言中是行不通的,所以每一步乘以10来计算,vis标记是否出现过*/
    #include<stdio.h>
    #include<string.h>
    #define 100000+100
    int vis[MAX];
    int main()
    {
    	int yu,t,n;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d",&n);
    		if(n==1)
    		{
    			printf("1
    ");
    			continue;
    		}
    		if(n<0)
    		{
    			printf("-");
    			n=-n;
    		}
    		printf("0.");
    		memset(vis,0,sizeof(vis));
    		yu=1,vis[1]=1;
    		while(yu)
    		{
    			yu*=10;
    			printf("%d",yu/10);
    			yu%=10;
    			if(vis[yu])
    			break;
    			vis[yu]=1;
    		}
    		printf("
    ");
    	}
    	return 0;
    }

     
  • 相关阅读:
    第36课 经典问题解析三
    第35课 函数对象分析
    67. Add Binary
    66. Plus One
    58. Length of Last Word
    53. Maximum Subarray
    38. Count and Say
    35. Search Insert Position
    28. Implement strStr()
    27. Remove Element
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273742.html
Copyright © 2011-2022 走看看