UVA 10494 If We Were a Child Again 解题报告

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1435

题目大意:给定两个数 第一个是大数 第二个是int 数, 两种运算  / 或 %  求所得的值

题目考点:大数 / 小数

解题思路,模拟除法

题目代码:

View Code
 1 // File Name: 10494.c
 2 // Author: darkdream
 3 // Created Time: 2013年01月28日 星期一 19时07分49秒
 4 
 5 #include<stdio.h>
 6 #include<string.h>
 7 #include<stdlib.h>
 8 #include<time.h>
 9 #include<math.h>
10 char a[1000];
11 long long int n ;
12 void change(char a[],int b[])
13 { int i ;
14     for (i = 0 ;i < strlen(a) ; i++ )
15         b[i] = a[i] - '0';
16 
17 }
18 void op1(int b[], int t , long long int n  )
19 {
20     int k = strlen(a);
21     long long int temp = b[0];
22 
23     int  i  , j = 0  ,  s[1000], p = 0;
24     for (i = 0 ;i < k ; i ++ )
25     {   
26         if (i >= 1)
27             temp = temp *10 + b[i];
28 
29         if (temp >= n || p)
30         {    if (temp < n)
31             s[j++] = 0 ;
32             else 
33             {
34                 s[j++] = temp / n;
35                 temp = temp % n ;
36                 p = 1;
37             }
38         }
39 
40 
41     }
42     if (t == 1)
43     {
44         if (j == 0)
45             printf("0");
46         else 
47             for (i = 0; i < j  ; i++)
48                 printf("%d",s[i]);
49 
50     }else
51         printf("%lld",temp);
52     printf("\n");
53 
54 
55 
56 
57 
58 }
59 
60 int main(){
61     while (scanf("%s",a) != EOF)
62     {
63         char temp[10];
64         int  b[1000];
65         change(a,b);
66         long long int ans;
67         scanf("%s",temp);
68         scanf("%lld",&n);
69         if (strchr(temp,'/'))
70             op1(b,1,n);
71         else 
72             op1(b,2,n);
73 
74 
75 
76     }
77 
78     return 0 ;
79 }
原文地址:https://www.cnblogs.com/zyue/p/2880456.html