• 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 }
  • 相关阅读:
    vs2017 vs2019 打开cs文件提示无法识别的GUID格式
    A股和B股票的区别?
    选股:“均线是水,K线是舟,量是马达!”的选美理念!
    什么是K线?K线的详解!
    5日均线MACD
    炒股的常见技术指标
    选股票几大原则:趋势原则,强势原则,分批原则
    金融蝴蝶效应
    股市里的大户和散户
    期货平仓/强制平仓/爆仓-股市平仓建仓
  • 原文地址:https://www.cnblogs.com/zyue/p/2877420.html
Copyright © 2020-2023  润新知