## 424 - Integer Inquiry

Moderator: Board moderators

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 424 - Integer Inquiry

Use code tags.

Input

Code: Select all

``````1
1
1
1
1
1
1
1
1
1
0
``````
Acc Output

Code: Select all

``10``
Don't forget to remove your code after getting accepted.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

### Re: 424 - Integer Inquiry

The udebug code for this problem has to be wrong.
The java AC solution reads big integers until the number equals 0 and keeps the running sum.
Last edited by mgavin2 on Thu Feb 26, 2015 4:56 am, edited 1 time in total.
all that matters is AC

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

### Re: 424 - Integer Inquiry

If you think that this is wrong:
http://www.udebug.com/UVa/424
Then please provide input that it is failing.

For your code, change line 114 to:
Check input and AC output for thousands of problems on uDebug!

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

### Re: 424 - Integer Inquiry

input:

Code: Select all

``````1a
0
``````
output

Code: Select all

``````29
``````
The java solution would throw a runtime error..

also:
input

Code: Select all

``````-2
-1
0
``````
gives

Code: Select all

``````*3
``````
when the java solution should give -3

input:

Code: Select all

``````000
0
``````
gives nothing, when the java AC solution would report 0.

I know the problem statement says:
The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
but we aren't accustomed to problem statements always being right. It could be misleading in saying that you should discard input that is negative or contains characters other than digits. For example, problem 1585 where it says "There is no spaces between `O' and `X'. " , when there could be spaces elsewhere.
all that matters is AC

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

### Re: 424 - Integer Inquiry

The judge's input for this problem only contains digits and has no leading zeros.
It doesn't matter what you or the uDebug solution prints for invalid input.
Check input and AC output for thousands of problems on uDebug!

nhimran
New poster
Posts: 2
Joined: Wed Feb 11, 2015 6:35 pm

### Getting WA

I am getting wrong answer with my code. can anyone help me please ?

Code: Select all

``````#include<stdio.h>
#include<string.h>

#define siz 120
int main()
{
char num[102],sum[siz],tmp;
int i,j,ln,res,carry;

memset(sum,0,siz);

while(1){
scanf("%s",num);

if(strcmp(num,"0")==0){
break;
}

ln=strlen(num);

for(i=0;i<ln/2;i++){
tmp = num[i];
num[i]=num[ln-1-i];
num[ln-1-i]=tmp;
}
carry = 0;
for(i=0;i<siz;i++){
if(i<ln){
j=num[i]-'0';
}
else{
j=0;
}
sum[i]= carry+sum[i]+j;
if(sum[i]>9){
sum[i]=sum[i]%10;
carry = 1;
}
else{
carry=0;
}
}
}

for(i=siz-1;i>=0;i--){
if(sum[i]!=0)break;
}

for(;i>=0;i--){
printf("%d",sum[i]);
}

return 0;
}

``````

xYinXiao
New poster
Posts: 1
Joined: Tue Nov 10, 2015 6:56 pm

### Re: 424 - Integer Inquiry

Hello there, I actually have a problem with my code. The problem here is that I don't know where the problem is. The output should be correct, but as I try to submit my code, it says WA. Would someone be so kind to find the issue in my code?

Code: Select all

``````#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int main() {
vector<int> sum(1000, 0);
char str[101];

int i;
while(scanf("%s", str) && str[0] != '0') {
i = 0;
int n = strlen(str);
while(i < n) {
sum[i] += (str[n - 1 - i] - '0');
i++;
}
}
int last = 0;
for(i = 0;i < 1000;i++) {
sum[i + 1] += (sum[i] / 10);
sum[i] %= 10;
if (sum[i] != 0)
last = i;
}
for(i = last;i >= 0;i--) {
printf("%d", sum[i]);
}
return 0;
}
``````
Thanks~