#10237: zj過了Uva過不了0.0


chinesex88 (Haruka)

學校 : 高雄市立高雄高級中學
編號 : 43137
來源 : [220.133.4.59]
最後登入時間 :
2024-11-16 14:39:26
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [163.32.78.48] | 發表日期 : 2015-09-16 17:06

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
int main()
{
 int x[105], y[105];
 long long int xs, ys;
 while (scanf("%lld%lld", &xs, &ys))
 {
     memset(x,0,sizeof(x));memset(y,0,sizeof(y));
  if (xs==0&&ys == 0)break;
  int tmpi = 0;
  while (xs)
  {
   x[tmpi] = xs % 10;
   tmpi++;
   xs /= 10;
  }
  int tmp = 0;
  while (ys)
  {
   y[tmp] = ys % 10;
   ys /= 10;
   tmp++;
  }
  //for (int i = 0; i < tmp; i++)
   //printf("%d %d\n", x[i], y[i]);
  int carry = 0;
  int len = std::min(tmp, tmpi);
  for (int i = 0; i <len+1; i++)
   if (x[i] + y[i]>=10) { carry+=(x[i]+y[i])/10; x[i + 1] +=( (x[i] + y[i]) / 10); }
  if (!carry)printf("No carry operation.\n");
  else if (carry == 1)printf("1 carry operation.\n");
  else printf("%d carry operations.\n", carry);
 }
 return 0;
}

 

想不出原因

 
#10242: Re:zj過了Uva過不了0.0


prisoner (prisoner)

學校 : 不指定學校
編號 : 51782
來源 : [208.58.75.181]
最後登入時間 :
2015-10-02 07:28:18
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [208.58.75.181] | 發表日期 : 2015-09-17 00:57

#include
#include
#include
#include
int main()
{
 int x[105], y[105];
 long long int xs, ys;
 while (scanf("%lld%lld", &xs, &ys))
 {
     memset(x,0,sizeof(x));memset(y,0,sizeof(y));
  if (xs==0&&ys == 0)break;
  int tmpi = 0;
  while (xs)
  {
   x[tmpi] = xs % 10;
   tmpi++;
   xs /= 10;
  }
  int tmp = 0;
  while (ys)
  {
   y[tmp] = ys % 10;
   ys /= 10;
   tmp++;
  }
  //for (int i = 0; i < tmp; i++)
   //printf("%d %d\n", x[i], y[i]);
  int carry = 0;
  int len = std::min(tmp, tmpi); <----------------------- it is wrong here.
  for (int i = 0; i <len+1; i++)
   if (x[i] + y[i]>=10) { carry+=(x[i]+y[i])/10; x[i + 1] +=( (x[i] + y[i]) / 10); }
  if (!carry)printf("No carry operation.\n");
  else if (carry == 1)printf("1 carry operation.\n");
  else printf("%d carry operations.\n", carry);
 }
 return 0;
}

 

想不出原因

try this test


9999999999 1

 
ZeroJudge Forum