Problem ID :h176. A.A+B Problem

New Thread

User 請問哪裡錯

austins96432 SendIMessage
涼麵趁熱吃

h176. A.A+B Problem | From: 111.250.163.106 | Post Date:2020-01-30 08:35:07.0

如題,謝謝! 
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int main(void)
{
int n;
cin>>n;
while(n--)
{
queue <long long int> x,y,z;
long long int a,b,c,count=0;
string number;
cin>>number;
for(int i=0;i<=(number.length()-1)/2;i++)
{
for(int j=i+1;j<=(number.length()-1)*2/3;j++)
{
if(i>=1)
{
if(number[0]=='0') break;
}
if(j-(i+1)>=1)
{
if(number[i+1]=='0') break;
}
if(number.length()-1-(j+1)>=1)
{
if(number[j+1]=='0') break;
}
a=0;
for(int k=0;k<=i;k++)
{
a=a*10+number[k]-'0';
}
b=0;
for(int k=i+1;k<=j;k++)
{
b=b*10+number[k]-'0';
}
c=0;
for(int k=j+1;k<=number.length()-1;k++)
{
c=c*10+number[k]-'0';
}
if(a+b==c)
{
count++;
x.push(a);
y.push(b);
z.push(c);
}
}
}
if(count>0)
{
cout<<count<<"\n";
while(!x.empty())
{
cout<<x.front()<<" + "<<y.front()<<" = "<<z.front()<<"\n";
x.pop();
y.pop();
z.pop();
}
}
else
{
cout<<"0\n";
}
}
return 0;
 


文章類型: 一般 | Reply | Back

New Thread

ZeroJudge Forum