为什么只有40分???!!!

P1303 A*B Problem

石破天惊 @ 2016-01-28 22:56:04

const met=200;
var
i,j,la,lb,len:longint;
sa,sb:string;
m:longint;
a:array[1..met]of longint;
b:array[1..met]of longint;
c:array[1..met]of longint;
begin
for i:=1 to met do c[i]:=0;
readln(sa);
readln(sb);
la:=length(sa);
for i:=1 to la do a[i]:=ord(sa[la-i+1])-48;
lb:=length(sb);
for i:=1 to lb do b[i]:=ord(sb[lb-i+1])-48;
for i:=1 to la do
for j:=1 to lb do
c[i+j-1]:=c[i+j-1]+a[i]*b[j];
len:=la+lb;
for i:=1 to len do
    begin
    c[i+1]:=c[i+1]+c[i] div 10;
    c[i]:=c[i] mod 10;
    end;
while c[len]=0 do dec(len);
m:=c[len];
while m>0 do
    begin
    c[len]:=m mod 10;
    m:=m div 10;
    inc(len);
    end;
for i:=len-1 downto 1 do
write(c[i]);
readln;
end.

by 石破天惊 @ 2016-01-28 23:13:12

求助/i


by 石破天惊 @ 2016-01-28 23:14:26

[codep ]writeln("Hello world!")[/codep ]


by 汪力宾 @ 2016-01-30 16:14:31

var
  s1,s2:ansistring;
  a,b,c:array[1..100000] of integer;
  jw,la,lb,i,j,ws:longint;
begin
  readln(s1);
  readln(s2);
  if (s1='0')or(s2='0') then
  begin
    writeln(0);
    halt;
  end; 
  la:=length(s1);
  lb:=length(s2);
  for i:=1 to la do
    a[i]:=ord(s1[la-i+1])-48;
  for i:=1 to lb do
    b[i]:=ord(s2[lb-i+1])-48;
  for i:=1 to lb do
  begin
    jw:=0;
    for j:=1 to la+1 do
    begin
     c[i+j-1]:=c[i+j-1]+a[j]*b[i]+jw;
     jw:=c[i+j-1] div 10;
     c[i+j-1]:=c[i+j-1] mod 10;
    end;
  end;
  ws:=la+lb;
  if c[ws]=0  then
    dec(ws);
  for i:=ws downto 1 do
    write(c[i]);
end.

by 汪力宾 @ 2016-01-30 16:15:13

自己看吧


by xunzhen @ 2016-02-02 21:09:36

水题一道,我用的C语言(压位)。

#include<stdio.h>
#include<stdlib.h> 
#include<string.h>
char s[30000],l[30000];
long long a[30001],b[30001],c[60000],al,bl,cl,i,j,x;
int main()
{gets(s);
 al=strlen(s);
 for (i=0;i<(5-al%5)%5;i++){
   strcpy(l,s);
   strcpy(s,"0");
   strcat(s,l);
 }
 //puts(s);
 if (al%5!=0) al=(al/5+1)*5;
 for (i=0;i<al/5;i++)
   a[i+1]=(s[al-i*5-1]-'0')+(s[al-i*5-2]-'0')*10+(s[al-i*5-3]-'0')*100+(s[al-i*5-4]-'0')*1000+(s[al-i*5-5]-'0')*10000;
 gets(s);
 bl=strlen(s);
 for (i=0;i<(5-bl%5)%5;i++){
   strcpy(l,s);
   strcpy(s,"0");
   strcat(s,l);
 }
 if (bl%5!=0) bl=(bl/5+1)*5;
 for (i=0;i<bl/5;i++)
   b[i+1]=(s[bl-i*5-1]-'0')+(s[bl-i*5-2]-'0')*10+(s[bl-i*5-3]-'0')*100+(s[bl-i*5-4]-'0')*1000+(s[bl-i*5-5]-'0')*10000;
 for (i=1;i<=bl/5;i++) 
   for (j=1;j<=al/5;j++)
     c[i+j-1]=c[i+j-1]+a[j]*b[i];
 for (i=1;i<=al/5+bl/5;i++){
   c[i+1]=c[i+1]+c[i]/100000;
   c[i]=c[i]%100000;  
 }
 x=0;
 for (i=al/5+bl/5;i>0;i--){
   if (c[i]!=0 && x==0){
     x=1; cl=i;
   }
   if (x){    
     if(i<cl){
       if (c[i]<10) printf("0");
       if (c[i]<100) printf("0");
       if (c[i]<1000) printf("0");
       if (c[i]<10000) printf("0");
     }
     printf("%d",c[i]);
   }
 }
 if (x==0) printf("0");
 puts("");
 system("pause");
 return 0;
}

by 饕餮吃题目 @ 2016-08-10 18:53:50

我直接写sum:=a*b都有四十分哈哈哈!


by YYX6 @ 2016-08-14 15:38:48

@caiyuelin我也是


by wangzh @ 2016-08-16 08:53:14

#include<iostream>  
#include<cstring>  
#include<string>  
#include<cstdio>  
using namespace std;  
int x[10001]={0},y[10001]={0},z[10001]={0};//一定要加上={0}  
int main()  
{  
    int temp;  
    string a,b;  
    int l=0;  
    cin>>a>>b;  
    int c=a.size()-1,d=b.size()-1;  
    for(int i=0;i<=c;i++)    
    x[i]=a[i]-48;    
    for(int i=0;i<=d;i++)    
    y[i]=b[i]-48;   
    for(int i=0;i<=c/2;i++)    
{    
    temp=x[i];    
    x[i]=x[c-i];    
    x[c-i]=temp;    
}    
    for(int i=0;i<=d/2;i++)    
{    
    temp=y[i];    
    y[i]=y[d-i];    
    y[d-i]=temp;    
}    
    for(int i=0;i<=c;i++)  
    for(int j=0;j<=d;j++)  
{  
    z[i+j]=x[i]*y[j]+z[i+j];  
    if(z[i+j]>9)  
{  
    z[j+i+1]+=z[j+i]/10;  
    z[j+i]-=z[j+i]/10*10;  
}  
    l=i+j;  
}  
    l++;  
    while(z[l]==0&&l!=0)l--;  
    for(int i=l;i>=0;i--)  
    cout<<z[i];  
    return 0;  
}

by wangzh @ 2016-08-16 08:53:55

自己看吧,C++的


|