Thank you..
I tried with your input, my output is exactly same as yours..
Here, I post my code.. Wen I copied ur output, it looked like thr is an extra blank line after last output(like \n\n), so I tried adding extra newline after d last output, still I got d same WA.. Nywy, this is my original code which takes strictly 10inputs..
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void get_klaudia_apples(const char* total, const char* extra, char* klaudia) {
int i = strlen(total) - 1;
int j = strlen(extra) - 1;
char add_result[105] = { 0 };
if(i > 100 || j > 100) return;
int k = 103;
unsigned int carry = 0;
while(i >= 0) {
int tmp = (*(total + i) - '0');
if(j >= 0)
tmp += (*(extra + j) - '0');
if(carry) {
tmp += carry;
carry = 0;
}
if(tmp > 9) {
carry = tmp / 10;
tmp = tmp % 10;
}
*(add_result + k) = '0' + tmp;
i --;
j --;
k --;
}
while(carry) {
int tmp = carry % 10;
carry /= 10;
*(add_result + k) = '0' + tmp;
k --;
}
i = 0; j = k + 1;
while( j < 104) {
*(add_result + i) = *(add_result + j);
i ++;
j ++;
}
*(add_result + i) = 0;
j = 0;
unsigned int remainder = 0, first_flag = 1;
i = 0;
while(i < strlen(add_result)) {
unsigned int dividend = 0;
dividend = (remainder * 10);
dividend += *(add_result + i) - '0';
remainder = 0;
i ++;
if(dividend == 0) {
*(klaudia + j) = '0';
first_flag = 1;
remainder = 0;
j ++;
continue;
}
if(first_flag) {
if((strlen(add_result) - i) >= 0 && dividend < 2) {
dividend = (dividend * 10) + (*(add_result + i) - '0');
i ++;
}
first_flag = 0;
}
unsigned int quotient = dividend / 2;
remainder = dividend % 2;
*(klaudia + j) = quotient + '0';
j ++;
}
*(klaudia + j) = 0;
return;
}
void get_natalia_apples(const char* total, const char* klaudia, char* natalia) {
int totallen = strlen(total), klaudialen = strlen(klaudia);
unsigned int borrow = 0;
int i = totallen - 1, j = klaudialen - 1;
int k = totallen - 1;
while(i >= 0) {
unsigned int tmp1 = *(total + i) - '0', tmp2 = 0;
i --;
if(j >= 0) {
tmp2 = *(klaudia + j) - '0';
j --;
}
if(borrow) {
if(tmp1) {
tmp1 --;
borrow = 0;
} else {
tmp1 = 9;
borrow = 1;
}
}
unsigned int tmp3 = 0;
if(tmp2) {
if(tmp1 < tmp2) {
borrow = 1;
tmp1 += 10;
}
tmp3 = tmp1 - tmp2;
} else {
tmp3 = tmp1;
}
if(tmp3 == 0 && i < 0) {
}
else {
*(natalia + k) = tmp3 + '0';
k --;
}
}
i = 0, j = k + 1;
while( j < totallen) {
*(natalia + i) = *(natalia + j);
i ++;
j ++;
}
*(natalia + i) = 0;
return;
}
int main() {
unsigned int iters = 10;
while(iters -- > 0) {
char total_apples[105] = { 0 }; //10 pow 100 is 101characters, 105 shud b more than enuf.
char extra_apples[105] = { 0 };
scanf("%s", total_apples);
scanf("%s", extra_apples);
char klaudia_apples[105] = { 0 };
char natalia_apples[105] = { 0 };
get_klaudia_apples(total_apples, extra_apples, klaudia_apples);
printf("%s\n", klaudia_apples);
get_natalia_apples(total_apples, klaudia_apples, natalia_apples);
printf("%s\n", natalia_apples);
}
return 0;
}
Sorry, poor coding.. no comments in d code either..
Input output for ref.. (with ur testcases.. Had changed no of iters to 3, just for this..)
[root@localhost spoj]# ./JULKA output_JULKA
[root@localhost spoj]# cat input_JULKA
100
56
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
9876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210
109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876548
[root@localhost spoj]# cat output_JULKA
78
22
8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
4993209877099320987709932098770993209877099320987709932098770993209877099320987709932098770993209879
4883333333888333333388833333338883333333888333333388833333338883333333888333333388833333338883333331
[root@localhost spoj]# cat output_JULKA_spoj
78
22
8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
4993209877099320987709932098770993209877099320987709932098770993209877099320987709932098770993209879
4883333333888333333388833333338883333333888333333388833333338883333333888333333388833333338883333331
[root@localhost spoj]#
Plz help..