zoukankan      html  css  js  c++  java
  • 【习题 3-8 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    余数出现循环节。 就代表出现了循环小数。

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    
    int a,b;
    int bo[4000];
    vector <int> v;
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	    freopen("rush_out.txt","w",stdout);
    	#endif
    	int kase = 0;
    	while (~scanf("%d%d",&a,&b)){
    		kase++;
    	    memset(bo,0,sizeof bo);
    	    v.clear();
    		
    		printf("%d/%d = ",a,b);
    		printf("%d.",a/b);
    
    		int cnt = 0;
    
    		if (a%b==0){
    		 	cnt = 1;
    		 	printf("(0)");
    		}else{
        	 	int x = a%b;
        	 	v.push_back(x*10/b);
        	 	bo[x] = 1;
        	 	int now = 1;
        	 	x = x*10%b;
          		while (1){
          		 	if (bo[x]){
          		 		cnt = now-bo[x]+1;
          		 		int j = 0;
          		 		for (int i = 0;i < bo[x]-1;i++) {
          		 		    j++;
          		 		    if (j>50) break;
          		 			putchar(v[i]+'0');
          		 		}
          		 		putchar('(');
          		 		for (int i = bo[x]-1;i < (int) v.size();i++) {
          		 			j++;
          		 			if (j > 50){
          		 				printf("...");
          		 			 	break;
          		 			}
          		 			putchar(v[i]+'0');
    
          		 		}
          		 		putchar(')');
          		 	 	break;
          			}
          			now++;
          			bo[x] = now;
          			v.push_back(x*10/b);
          			x = x*10%b;
          		}
    
      		}
      		puts("");
      		printf("   %d = number of digits in repeating cycle",cnt);
      		puts("");
      		puts("");
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    Array.from和 map的相同用法
    js复制数组的各种方式
    set集合转数组的两种方法
    关于set集合去重的问题
    Object.is判断两个值是否相等
    数组排序
    函数默认值的取值
    标准索引
    pgsql update left join
    linux pgsql
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7803448.html
Copyright © 2011-2022 走看看