11258 - String Partition
Moderator: Board moderators
11258 - String Partition
I tried to solve this using DP. But was getting WA.
Can someone give me tricky i/o ?
Thanks
Can someone give me tricky i/o ?
Thanks
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
I too felt the same but got so many WAs.
Can you anything wrong with this code ?
Can you anything wrong with this code ?
Code: Select all
======= Removed ============
Last edited by pvncad on Sat Aug 04, 2007 4:07 pm, edited 1 time in total.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
If i didnt misunderstand your code
It should be
isnt it?[/code]
another less important thing:
you dont need another variable max..
sum[0] is the result![:)](./images/smilies/icon_smile.gif)
Code: Select all
long long last = num[j];
Code: Select all
long long last = num[i+j];
another less important thing:
you dont need another variable max..
sum[0] is the result
![:)](./images/smilies/icon_smile.gif)
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
isnt there anyway without DP. I tryed but it is WA. is there any tricky input? or ......?
please help
Code: Select all
#include <stdio.h>
#include <string.h>
#define MAX 4294967295L
int main()
{
char str[200];
long long num,sum,i;
int test;
scanf("%d%*c",&test);
while(test--)
{
gets(str);
sum = 0;
num = 0;
for(i=0;str[i];i++)
{
if((long long)(num*10 + str[i]-48) > MAX)
{
sum += num;
num = 0;
i--;
}
else
num = num*10 + str[i]-48;
}
sum += num;
printf("%lld\n",sum);
}
return 0;
}
Non-negative 32-bit signed integer must be in range 0..2147483647, i.e. the answer for string "4294967295" should be "429496734"
Last edited by mf on Wed Aug 15, 2007 12:20 pm, edited 2 times in total.
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
are you talking about signed or unsigned int???
sorry i cant undstnd. may u clarify again.
what abt 2147483648
sorry i cant undstnd. may u clarify again.
what abt 2147483648
Last edited by newton on Wed Aug 15, 2007 12:21 pm, edited 1 time in total.
-
- New poster
- Posts: 13
- Joined: Fri Nov 03, 2006 2:53 pm
- Location: bangladesh
- Contact:
11258 wa
hi
i m getting wrong ans with 11258 i cant find why ?
can any one help me i am giving the code here.
i m getting wrong ans with 11258 i cant find why ?
can any one help me i am giving the code here.
Code: Select all
//string partition 11258
#include<stdio.h>
#define LIMIT 2147483647L
int main(void)
{
long long N,num,Tnum,prevnum,i,j;
char a[250];
scanf("%lld",&N);
for(i=0; i<N; i++)
{
scanf("%s",a);
num=0;Tnum=0;
for(j=0; a[j]; j++)
{
prevnum=num;
num = num*10 + (a[j]-'0');
if(num>LIMIT)
{
Tnum=Tnum+prevnum;
num=0;
j--;
}
}
Tnum = Tnum + num;
printf("%lld\n",Tnum);
}
return 0;
}