11076 - Add Again

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

Moderator: Board moderators

Rezwanul Islam Maruf
New poster
Posts: 2
Joined: Thu Oct 13, 2011 2:14 am

Re: 11371 - Number Theory for Newbies

Post by Rezwanul Islam Maruf » Fri Oct 14, 2011 2:09 am

help me plz wht did I make wrong :'(



#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

long long asending_digit(long long n)
{
long long num,p,temp,arr[200],i,j,k,l;
i=0;
p=n;
while(n)
{
arr=n%10;
n=n/10;
i++;
}
if(i==1)return p;
sort(arr,arr+i);
num=0;int m=1;


k=1;
while(arr[0]==0)
{
swap(arr[0],arr[k]);
k++;
}



for(j=i-1;j>=0;j--)
{
num=num+m*arr[j];
m=m*10;
}


return num;
}

long long decendig_digit(long long n)
{
long long num,p;
int arr[200],i,j,k;
i=0;
p=n;
while(n)
{
arr=n%10;
n=n/10;
i++;
}
if(i==1)return p;
sort(arr,arr+i);
k=i-1;num=0;int m=1;

for(j=0;j<i;j++)
{
if(j==0)num=num+arr[j];
else
num=num+m*arr[j];
m=m*10;
}


return num;
}

int main()
{
long long num,rev,temp,mul,div;
int i,arr[500],len;

while(scanf("%lld",&num)==1)
{
num=asending_digit(num);
rev=decendig_digit(num);



if(num>rev)mul=num-rev;

else mul=rev-num;

div=mul/9;

if(num<0)printf("0 - 0 = 0 = 9 * 0\n");
else if(num>rev)
printf("%lld - %lld = %lld = 9 * %lld\n",num,rev,mul,div);
else
printf("%lld - %lld = %lld = 9 * %lld\n",rev,num,mul,div);
}

return 0;
}

shaishab roy
New poster
Posts: 2
Joined: Mon Jul 22, 2013 7:37 pm
Location: Bangladesh
Contact:

Why got WA please help me?

Post by shaishab roy » Mon Jul 22, 2013 8:09 pm

11076 - Add Again
http://uva.onlinejudge.org/external/110/11076.html
my solution code :
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
void print(int p,unsigned long long div1);
unsigned long long input[15],divnpr,count1,nprValue,subSum,flag;
unsigned long long npr[14]={1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600};
int n,i,j,arr[100],c;
double temSum,multiplayer;
int main ()
{
//freopen("in.txt","r",stdin);
while(scanf("%d",&n)==1)
{
if(n==0)
break;
divnpr=1;
temSum=0;
flag=0;
c=0;
for(i = 0; i <n ; i++)
{
scanf("%llu",&input);
}
std::sort (input,input+n);
count1=1;
for(i=1;i<n;i++)
{
if(input==input[i-1])
{
count1+=1;
}
else
{
divnpr*=npr[count1];
count1=1;
}
}
divnpr*=npr[count1];
nprValue=npr[n]/divnpr;
multiplayer=(double)nprValue/(double)n;
for(i = 0; i <n ; i++)
temSum+=multiplayer*(double)input;
subSum=(unsigned long long)temSum;
print(1,0);
if(flag==0)
printf("0");
else
for(i=c-1;i>=0;i--)
printf("%d",arr);
printf("\n");
}
return 0;
}
void print(int p,unsigned long long div1)
{
unsigned long long sum,mod;
sum=subSum+div1;
mod=sum%10;
div1=sum/10;
arr[c]=mod;
flag+=mod;
c++;
if(p!=n)
{
p++;
print(p,div1);
}
else
{
while(div1!=0)
{ mod=div1%10;
div1=div1/10;
arr[c]=mod;
flag+=mod;
c++;
}
}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why got WA please help me?

Post by brianfry713 » Tue Jul 23, 2013 1:25 am

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!

shaishab roy
New poster
Posts: 2
Joined: Mon Jul 22, 2013 7:37 pm
Location: Bangladesh
Contact:

Re: Why got WA please help me?

Post by shaishab roy » Fri Jul 26, 2013 10:01 pm

solve without floating point but still WA!!!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why got WA please help me?

Post by brianfry713 » Sat Jul 27, 2013 3:57 am

Post your updated code.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 110 (11000-11099)”