zoukankan      html  css  js  c++  java
  • UVa 10106 Product 【大数相乘】WA

    虽然是错的代码,但是还是想贴出来,最开始WA发现是没有考虑到乘积为0的情况,后来把a*0,0*a,a*0---0(若干个0),0--0(若干个0)*a都考虑进去了;可是还是WA,实在不懂先留在这儿。

     Product 

    The Problem

    The problem is to multiply two integers X, Y. (0<=X,Y<10250)

    The Input

    The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.

    The Output

    For each input pair of lines the output line should consist one integer the product.

    Sample Input

    12
    12
    2
    222222222222222222222222
    

    Sample Output

    144
    444444444444444444444444


    #include<stdio.h>
    #include<string.h>
    #define max 500
    int panduan(char a[])
    {
      int tag,flag=1;
      int i;
      for(i=0;a[i]!=''&&flag;i++)
      {
      	if(a[i]!='0')
      	{
      		flag=0;
      	}
      }
      if(flag)
      {
          if(i==1)
          return 1;
          else
          return 2;
      }
      else
      return 0;
    }
    int main()
    {
        int i,j;
        int len1,len2,len;
        int a[max],b[max],c[max];
        char str1[max],str2[max];
        while(~scanf("%s %s",&str1,&str2))
        {
            if(panduan(str1)==1||panduan(str2)==1)//判断两个相乘的数里面有没有'0'
            {
                printf("0
    ");
            }
            else if(panduan(str1)==2||panduan(str2)==2)//判断两个相乘的数里面如果出现0---0(若干个),则不处理这组数据
            {
                printf("
    ");
               continue;
            }
            else
            {
    
                memset(a,0,sizeof(a));
                memset(b,0,sizeof(b));
                memset(c,0,sizeof(c));
                len1=strlen(str1);
                len2=strlen(str2);
                for(i=0;i<len1;i++)
                 {
                a[i]=str1[len1-i-1]-'0';
                 }
                for(i=0;i<len2;i++)
                  {
                b[i]=str2[len2-i-1]-'0';
                  }
                for(i=0;i<len2;i++)
                  {
                for(j=0;j<len1;j++)
                c[i+j]+=b[i]*a[j];
                   }
            len=i+j;
            for(i=0;i<len;i++)
            {
                if(c[i]>=10)
                {
                c[i+1]+=c[i]/10;
                c[i]=c[i]%10;
                }
            }
            for(i=len;(c[i]==0)&&(i>=0);i--);
            for(j=i;j>=0;j--)
               printf("%d",c[j]);
               printf("
    ");
    
            }
        }
    }
    

      

  • 相关阅读:
    Linux服务器修改时区
    Linux磁盘IO查看
    passwd: 鉴定令牌操作错误
    Kubernetes 使用Nginx-Ingress实现蓝绿发布/金丝雀发布/AB测试【转】
    MySQL count 浅析【转】
    k8s pv,pvc无法删除问题【转】
    K8S 上部署 Redis-cluster 三主三从 集群【转】
    XtraBackup 备份加速【转】
    Gitlab+DRBD 高可用方案【转】
    Linux网卡bond的七种模式详解【转】
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4117874.html
Copyright © 2011-2022 走看看