Problem ID :h176. A.A+B Problem

New Thread

User 請問哪裡錯

austins96432 SendIMessage
涼麵趁熱吃

h176. A.A+B Problem | From: 111.250.93.176 | Post Date:2020-02-25 21:20:34.0

#include<iostream>
#include<string>
using namespace std;
int main(void)
{
int n;
cin>>n;
while(n--)
{
string number;
cin>>number;
long long int a[15]={0},b[15]={0},c[15]={0};
int L=number.length(),sum=0,check=0;
for(int i=1;i<=L/2;i++)
{
for(int j=i+1;j<=L*2/3;j++)
{
long aa=0,bb=0,cc=0;
if(i>2&&number[0]=='0') continue;
if(j-i>2&&number[i+1]=='0') continue;
if(L-j>2&&number[j+1]=='0') continue;
for(int ii=0;ii<i;ii++) aa=aa*10+(number[ii]-'0');
for(int ii=i;ii<j;ii++) bb=bb*10+(number[ii]-'0');
for(int ii=j;ii<L;ii++) cc=cc*10+(number[ii]-'0');
if((aa+bb)==cc)
{
sum++;
a[check]=aa;
b[check]=bb;
c[check]=cc;
check++;
}
}
}
if(sum==0) cout<<sum<<"\n";
else
{
cout<<sum<<"\n";
for(int i=0;i<check;i++)
{
cout<<a[i]<<" + "<<b[i]<<" = "<<c[i]<<"\n";
}
}
}
return 0;
}

 


文章類型: 一般 | Reply | Back
User Re:請問哪裡錯

sagit SendIMessage
sagit

h176. A.A+B Problem | From: 192.168.2.108 | Post Date:2020-03-03 15:57:25.0

先試試這三組數字:

1203
0018446744073709551616
16818904055562087446
 


文章類型: 一般 | Reply | Back
User Re:請問哪裡錯

austins96432 SendIMessage
涼麵趁熱吃

h176. A.A+B Problem | From: 118.166.143.44 | Post Date:2020-03-04 19:54:11.0

我仍然找不到錯,請問是哪裡出了問題
能再多給一點提示嗎?謝謝老師
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
int n;
cin>>n;
while(n--)
{
string number;
cin >> number;
long long int a[15]={0}, b[15]={0}, c[15]={0};
int L = number.length(), sum=0, check = 0;
for (int i = 0;i <= L/2; i++)
{
for(int j = i + 1;j <= L * 2 / 3;j++)
{
long long aa=0,bb=0,cc=0;
if(i >= 1 && number[0] == '0') break;
if(j-i >= 2&&number[i+1] == '0') break;
if(L-j >= 2&&number[j]=='0') break;
for(int ii=0;ii<i;ii++) aa=aa*10+(number[ii]-'0');
for(int ii=i;ii<j;ii++) bb=bb*10+(number[ii]-'0');
for(int ii=j;ii<L;ii++) cc=cc*10+(number[ii]-'0');
if((aa+bb)==cc)
{
sum++;
a[check]=aa;
b[check]=bb;
c[check]=cc;
check++;
}
}
}
if(sum==0) cout<<sum<<"\n";
else
{
cout<<sum<<"\n";
for(int i=0;i<check;i++)
{
cout<<a[i]<<" + "<<b[i]<<" = "<<c[i]<<"\n";
}
}
}
return 0;
 


文章類型: 一般 | Reply | Back
User Re:請問哪裡錯

sagit SendIMessage
sagit

h176. A.A+B Problem | From: 192.168.2.108 | Post Date:2020-03-06 10:46:43.0

試了一下。
16818904055562087446
這組應該是輸出

1
1681890 + 405556 = 2087446
但你的程式是輸出 0
 


文章類型: 一般 | Reply | Back
User Re:請問哪裡錯

austins96432 SendIMessage
涼麵趁熱吃

h176. A.A+B Problem | From: 118.166.147.224 | Post Date:2020-03-08 10:26:23.0

我修改了一下,但還是錯了
請問還有哪裡沒有考慮到嗎
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
int n;
cin>>n;
while(n--)
{
string number;
cin>>number;
int a[15][30],b[15][30],c[15][30];
for(int i=0;i<15;i++)
{
for(int j=0;j<30;j++)
{
a[i][j]=b[i][j]=c[i][j]=0;
}
}
int L=number.length(),sum=0,count = 0;
for (int i=0;i<=L/3;i++)
{
for(int j=i+1;j<=((L-1)*2)/3;j++)
{
int aa[30]={0},bb[30]={0},cc[30]={0};
if(i>=1&&number[0]=='0') continue;
if(j-i>=2&&number[i+1]=='0') continue;
if((L-1)-j>=2&&number[j+1]=='0') continue;
for(int ii=i,jj=0;ii>=0;ii--,jj++)
{
aa[jj]=number[ii]-'0';
}
for(int ii=j,jj=0;ii>=i+1;ii--,jj++)
{
bb[jj]=number[ii]-'0';
}
for(int ii=L-1,jj=0;ii>=j+1;ii--,jj++)
{
cc[jj]=number[ii]-'0';
}
int cc_2[30]={0},check=1;
for(int ii=0;ii<30;ii++)
{
cc_2[ii]+=aa[ii]+bb[ii];
if(cc_2[ii]>=10)
{
cc_2[ii+1]++;
cc_2[ii]-=10;
}
}
for(int ii=0;ii<30;ii++)
{
if(cc_2[ii]!=cc[ii])
{
check=0;
break;
}
}
if(check==1)
{
for(int ii=0;ii<30;ii++)
{
a[count][ii]=aa[ii];
b[count][ii]=bb[ii];
c[count][ii]=cc[ii];
}
sum++;
count++;
}
}
}
if(sum==0) cout<<sum<<"\n";
else
{
cout<<sum<<"\n";
for(int i=0;i<count;i++)
{
int check_a,check_b,check_c;
for(check_a=29;check_a>=0;check_a--)
{
if(a[i][check_a]!=0) break;
}
for(check_b=29;check_b>=0;check_b--)
{
if(b[i][check_b]!=0) break;
}
for(check_c=29;check_c>=0;check_c--)
{
if(c[i][check_c]!=0) break;
}
if(check_a==-1)
{
cout<<"0";
}
else
{
for(int j=check_a;j>=0;j--) cout<<a[i][j];
}
cout<<" + ";
if(check_b==-1)
{
cout<<"0";
}
else 
{
for(int j=check_b;j>=0;j--) cout<<b[i][j];
}
cout<<" = ";
if(check_c==-1)
{
cout<<"0";
}
else
{
for(int j=check_c;j>=0;j--) cout<<c[i][j];
}
cout<<"\n";
}
}
}
return 0;
}

 


文章類型: 一般 | Reply | Back
User Re:請問哪裡錯

sagit SendIMessage
sagit

h176. A.A+B Problem | From: 192.168.2.108 | Post Date:2020-03-18 14:54:18.0

999999999999991100000000000000
輸出
2
9 + 99999999999991 = 100000000000000
99999999999999 + 1 = 100000000000000
你的程式輸出
1
9 + 99999999999991 = 100000000000000
 


文章類型: 一般 | Reply | Back
User Re:請問哪裡錯

austins96432 SendIMessage
涼麵趁熱吃

h176. A.A+B Problem | From: 124.219.6.236 | Post Date:2020-03-18 15:26:05.0

謝謝老師

終於對了

原來只是範圍的問題 XD

for(int i=1;i<=L/2;i++)
{
for(int j=i+1;j<=L-2;j++)

{ 

 


文章類型: 一般 | Reply | Back

New Thread

ZeroJudge Forum