224 - Kissin' Cousins

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Anupam Pathak
New poster
Posts: 7
Joined: Tue Jul 25, 2006 2:01 pm
Contact:

224 - Kissin' Cousins

Post by Anupam Pathak »

hi all,
I dont understand why is it not working......


#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main()
{
string a[100],c,d;
char b[100],f[100];
int x[100],j,k,max=0,sum,i=0,y=0;
while(1)
{
cin>>a;
if(a[0]=='0')
break;
x=a.length();
i++;
}
for(j=0;j<i;j++)
{
if(max<x[j])
max=x[j];
}
for(j=max-1;j>=0;j--)
{
sum=y;
for(k=0;k<i;k++)
{
if((x[k]-1)>=0)
{
int z=(int)(a[k][(x[k]-1)])-48;
sum=sum+z;
x[k]--;
}
}
y=(sum/10);
b[j]=(char)((sum%10)+48);
}
c=(string)b;
if(y==0)
f[0]='\0';
if(y!=0)
sprintf(f,"%d",y);
d=(string)f;
c=d+c;
cout<<c<<endl;
return 0;
}
Trying to reduce complexity of the World.
Post Reply

Return to “Volume 2 (200-299)”