uva465 解题报告

注意:细心决定成败

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

题目大意:检测进行运算的数和他们的结果

题目考点:大数 模拟

解题思路:检测,,前导0 的忽略;

解题代码:

View Code
  1 // File Name: uva465.c
  2 // Author: darkdream
  3 // Created Time: 2013年01月25日 星期五 20时41分37秒
  4 
  5 #include<stdio.h>
  6 #include<string.h>
  7 #include<stdlib.h>
  8 #include<time.h>
  9 #include<math.h>
 10 char stand[] = "2147483647";
 11 char a[1000],b[1000];
 12 void mu(int c[],int d[],int e[])
 13 {
 14     int i ,j, k ,t ; 
 15     for (i =0 ;i < strlen(a) ;i ++)
 16     {
 17         int s = 0 ;
 18         for (j = 0 ; j < strlen(b) ;j++)
 19         {
 20             t = c[i]*d[j] +s +e[i+j] ;
 21             s = t / 10 ;
 22             e[i+j] = t % 10 ;
 23         }
 24         for (j = i+j  ; j< 550 ; j++)
 25         {
 26             t = e[j] + s;
 27             s = t /10 ;
 28             e[j] = t %10 ;
 29         }
 30 
 31     }
 32 
 33 
 34 }
 35 void add(int a[] , int b[])
 36 {
 37     int i ;
 38     int s = 0 ;
 39     for (i = 0 ; i < 500 ;i ++)
 40     {
 41         int t  =  a[i] + b[i] +s;
 42         s =  t / 10 ;
 43 
 44         a[i] = t %10 ;
 45 
 46     }
 47 
 48 }
 49 int strle(char a[])
 50 {
 51     int i ;
 52   for (i = 0 ;i < strlen(a) ;i ++)
 53       if (a[i] != '0')
 54           break;
 55   return  strlen(a) - i ;
 56   
 57 }
 58 int  than(char a[])
 59 {
 60     if (strle(a) > strlen(stand))
 61         return 1 ;
 62     if (strle(a) == strlen(stand))
 63         if( strcmp(a,stand) >0)
 64             return 1;
 65         else
 66             return 0;
 67     if (strle(a) < strlen(stand))
 68        return 0; 
 69 }
 70 void change(char a[], int b[])
 71 {
 72 
 73     int i ;
 74     for (i = 0 ; i <strlen(a); i++)
 75         b[strlen(a) - i -1] = a[i] - '0';
 76 }
 77 void rechange(int a[], char b[])
 78 {
 79     int i ; 
 80     for (i = 500 ; i >= 0 ; i-- )
 81         if (a[i] != 0)
 82             break;
 83     int j ;
 84     if (i == -1)
 85         b[0] = '0';
 86     else 
 87     for (j = 0 ; j <= i ; j++)
 88         b[j] = a[i-j] + '0';
 89 
 90 
 91 }
 92 
 93 int main(){
 94     int i ;
 95     int  c[1000],d[1000];
 96     int  e[1000]; 
 97     while(scanf("%s",a) != EOF)
 98     {
 99         memset(c,0,sizeof(c));
100         memset(d,0,sizeof(d));
101         memset(e,0,sizeof(e));
102         char temp[10];
103         change(a,c);
104         scanf("%s",temp);
105         scanf("%s",b);
106        printf("%s %s %s\n",a,temp,b);
107       
108         if (than(a))
109             printf("first number too big\n");
110        if (than(b))
111             printf("second number too big\n");
112         change(b,d);
113         if(strchr(temp,'+'))
114         {
115             add (c,d);
116             memset(a,0,sizeof(a));
117             rechange(c,a);
118             if(than(a))
119                 printf("result too big\n");
120 
121 
122         }
123 
124         if(strchr(temp,'*'))
125         {
126             mu(c,d,e);
127             memset(a,0,sizeof(a));
128             rechange(e,a);
129             if (than(a))
130                 printf("result too big\n");
131         }     
132     }
133     return 0 ;
134 }

 

 

 

转载于:https://www.cnblogs.com/zyue/archive/2013/01/26/2877420.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值