426 - Fifth Bank of Swamp County
Moderator: Board moderators
-
- Experienced poster
- Posts: 151
- Joined: Wed Aug 21, 2002 12:07 am
- Location: Seoul, Korea
- Contact:
426 Fifth bank of swamp country why WA?? [resolved]
Hi, it looks like a simple problem. I use qsort() to sort all the transactions..
Getting many WAs..
anybody who received an AC please give some hints or tricky cases.
My code:
[cpp]
cut: spolier
[/cpp]
Getting many WAs..
anybody who received an AC please give some hints or tricky cases.
My code:
[cpp]
cut: spolier
[/cpp]
Last edited by Whinii F. on Thu Aug 28, 2003 7:38 pm, edited 2 times in total.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
No, there are no such cases. All amounts are <$1000000.
I ran Whinii's program against a very large testset and compared it with my AC output. No differences. Strange.
The only difference I see is in the way we handle dirty input.
My program:
Whinii's program:
But I can't tell if there are realy such cases in the judge's input.
I ran Whinii's program against a very large testset and compared it with my AC output. No differences. Strange.
The only difference I see is in the way we handle dirty input.
Code: Select all
2
93/10/15 1001 116.81
93/10/27 1000 840.85
93/10/26 1002 555.55
93/10/15 1001
93/10/27 1000 840.85
93/10/26 1002 555.555
Code: Select all
1000 840.85 93/10/27 1001 116.81 93/10/15 1002 555.55 93/10/26
1000 840.85 93/10/27 1001 0.00 93/10/15 1002 555.55 93/10/26
Code: Select all
1000 840.85 93/10/27 1001 116.81 93/10/15 1002 555.55 93/10/26
1000 840.85 93/10/27 1001 840.00 93/10/15 1002 555.555 93/10/26
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
No prob! That's what we're here for!
Had WA on this one for ages, looked at it again yesterday, and suddenly saw the light (I didn't handle the one cheque case correctly). I was so excited about finaly solving it, that I couldn't resist trying my luck on your program. That's the way it works.
Happy hunting,
-little joey
Had WA on this one for ages, looked at it again yesterday, and suddenly saw the light (I didn't handle the one cheque case correctly). I was so excited about finaly solving it, that I couldn't resist trying my luck on your program. That's the way it works.
Happy hunting,
-little joey
Why this code always give me Runtime Error for 426?
I have tried many times, it always gave me:
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Why??
[cpp]#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
struct src{
string date;
int check;
double money;
bool star;
};
src table[10000];
bool new_less(src a,src b){
return a.check<b.check;
}
void print(int n,int no){
if(n>=no)
return;
cout.width(4);
cout<<(table[n]).check;
if((table[n]).star){
cout<<'*';
cout.width(8);
}
else
cout.width(9);
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<<(table[n]).money<<' '<<(table[n]).date;
}
int main(){
int case_no,no,i,dx,t_int;
double t_double;
string t_string;
char bu;
cin>>case_no;
cin.get(bu);
cin.get(bu);
while(case_no--){
no=0;
while(cin.peek()!='\n'){
cin>>t_string>>t_int;
cin.get(bu);
if(cin.peek()!='\n')
cin>>t_double;
else
t_double=0.0;
if(t_double<1000000){
(table[no]).date=t_string;
(table[no]).check=t_int;
(table[no]).money=t_double;
no++;
}
cin.get(bu);
}
sort(table,table+no,new_less);
(table[0]).star=false;
for(i=1;i<no;i++)
if((table).check-(table[i-1]).check!=1)
(table).star=true;
else
(table).star=false;
if(no%3==0)
dx=no/3;
else
dx=no/3+1;
for(i=1;i<=ceil(double(no)/3.0);i++){
print(i-1,no);
cout<<" ";
print(i-1+dx,no);
cout<<" ";
print(i-1+dx*2,no);
cout<<endl;
}
if(case_no)
cout<<endl;
cin.get(bu);
}
return 0;
}
[/cpp]
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Why??
[cpp]#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
struct src{
string date;
int check;
double money;
bool star;
};
src table[10000];
bool new_less(src a,src b){
return a.check<b.check;
}
void print(int n,int no){
if(n>=no)
return;
cout.width(4);
cout<<(table[n]).check;
if((table[n]).star){
cout<<'*';
cout.width(8);
}
else
cout.width(9);
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<<(table[n]).money<<' '<<(table[n]).date;
}
int main(){
int case_no,no,i,dx,t_int;
double t_double;
string t_string;
char bu;
cin>>case_no;
cin.get(bu);
cin.get(bu);
while(case_no--){
no=0;
while(cin.peek()!='\n'){
cin>>t_string>>t_int;
cin.get(bu);
if(cin.peek()!='\n')
cin>>t_double;
else
t_double=0.0;
if(t_double<1000000){
(table[no]).date=t_string;
(table[no]).check=t_int;
(table[no]).money=t_double;
no++;
}
cin.get(bu);
}
sort(table,table+no,new_less);
(table[0]).star=false;
for(i=1;i<no;i++)
if((table).check-(table[i-1]).check!=1)
(table).star=true;
else
(table).star=false;
if(no%3==0)
dx=no/3;
else
dx=no/3+1;
for(i=1;i<=ceil(double(no)/3.0);i++){
print(i-1,no);
cout<<" ";
print(i-1+dx,no);
cout<<" ";
print(i-1+dx*2,no);
cout<<endl;
}
if(case_no)
cout<<endl;
cin.get(bu);
}
return 0;
}
[/cpp]
Run Time Error 426 (Why)?
Donot understand why gettting runtime Error?
Code: Select all
/*
Name: Fifth Bank of Swamp County
Number: 426
Type : adhoc\sorting
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 21/08/05 23:27
*/
#include<stdio.h>
#include<string.h>
#include<math.h>
//#include<conio.h>
struct bank{
char date[100];
int check;
double money;
char c;
};
bank mbank[2000];
void interchange(int x,int y)
{
bank temp;
temp=mbank[x];
mbank[x]=mbank[y];
mbank[y]=temp;
}
int partition(int p,int r){
int i,j,x;
x=mbank[r].check;
i=p-1;
for(j=p;j<=r-1;j++){
if(mbank[j].check<=x){
i=i+1;
interchange(i,j);
}
}
interchange(i+1,r);
return i+1;
}
void quicksort(int l,int h){
int j;
if(l<h){
j=partition(l,h);
quicksort(l,j-1);
quicksort(j+1,h);
}
}
int main(){
char input[1000];;
int n,i,j,count,col,temp,tempo,t;
// freopen("426.txt","r",stdin);
gets(input);
sscanf(input,"%d",&n);
gets(input);
for(i=0;i<n;i++){
j=1;
while(gets(input)){
if(strcmp(input,"")!=0){
sscanf(input,"%s %d %lf",&mbank[j].date,&mbank[j].check,&mbank[j].money);
mbank[j].c=' ';
// printf("%s %d %lf\n" ,mbank[j].date,mbank[j].check,mbank[j].money);
j++;
}
else {
break;
}
}
quicksort(1,j-1);
for(count=1;count<=j-1;count++){
// printf("%s %d %lf\n" ,mbank[count].date,mbank[count].check,mbank[count].money);
//
}
// printf("%d\n",j-1);
col=j-1;
// col=(int)ceil((j-1)/3);
// printf("%d\n",col);
temp=(int)floor(((j-1)+2)/3);
// printf("%d\n",temp);
/*
for(count=1;count<=temp;count++,printf("\n")){
tempo=(temp*0)+count;
if(tempo<=col){
printf("%4d %6.2lf %s",mbank[tempo].check,mbank[tempo].money,mbank[tempo].date);
}
printf(" ");
tempo=(1*temp)+count;
if(tempo<=col){
printf("%4d %6.2lf %s",mbank[tempo].check,mbank[tempo].money,mbank[tempo].date);
}
printf(" ");
tempo=(temp*2)+count;
if(tempo<=col){
printf("%4d %6.2lf %s",mbank[tempo].check,mbank[tempo].money,mbank[tempo].date);
}
printf(" ");
}
*/
for(count=1;count<=col;count++){
if(mbank[count+1].check!=mbank[count].check && mbank[count+1].check!=mbank[count].check+1){
mbank[count+1].c='*';
}
}
for(count=1;count<=temp;count++,printf("\n")){
for(t=0;t<3;t++){
tempo=(temp*t)+count;
if(tempo<=col){
printf("%4d%c %8.2lf %s",mbank[tempo].check,mbank[tempo].c,mbank[tempo].money,mbank[tempo].date);
// printf(" ");
}
printf(" ");
}
}
printf("\n");
}
// getch();
return 0;
}
-
- New poster
- Posts: 21
- Joined: Tue Jan 10, 2006 12:25 am
426 - Fifth Bank of Swamp County
Please can anyone give me the correct ouput for this :
Code: Select all
5
93/10/15 1001 116.81
93/10/27 1000 840.85
93/10/26 1002 555.55
93/10/26 1003 555.55
93/10/15 1001
93/10/27 1000 9999999.99
93/10/26 1002 555.555
93/10/01 998 .65
93/10/01 999 0123.89
93/10/05 996 29.99
93/10/06 993 116.52
93/10/12 995 418.00
93/10/15 1001 15045.00
93/10/27 1000 840.85
93/10/15 1003 15045.00
93/10/01 998 .65
93/10/01 999 0123.89
93/10/05 996 29.99
93/10/06 993 116.52
93/10/12 995 418.00
93/10/15 1001 15045.00
93/10/27 1000 840.85
93/10/15 1003 15045.00
93/10/15 1006
93/10/01 998 .65
93/10/01 999 0123.89
93/10/05 996 29.99
93/10/06 993 116.52
93/10/12 995 418.00
-
- New poster
- Posts: 21
- Joined: Tue Jan 10, 2006 12:25 am
-
- Learning poster
- Posts: 74
- Joined: Sat Jul 15, 2006 6:28 am
- Location: CUET , bangladesh
- Contact:
Salman,
you can change the following and get PE.
you can change the following and get PE.
Code: Select all
struct bank{
char date[10];
int check;
double money;
char c;
};
bank mbank[100000];
SHAKIL
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: Why this code always give me Runtime Error for 426?
boatfish wrote:I have tried many times, it always gave me:
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Why??
[cpp]#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
struct src{
string date;
int check;
double money;
bool star;
};
src table[10000];
bool new_less(src a,src b){
return a.check<b.check;
}
void print(int n,int no){
if(n>=no)
return;
cout.width(4);
cout<<(table[n]).check;
if((table[n]).star){
cout<<'*';
cout.width(8);
}
else
cout.width(9);
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<<(table[n]).money<<' '<<(table[n]).date;
}
int main(){
int case_no,no,i,dx,t_int;
double t_double;
string t_string;
char bu;
cin>>case_no;
cin.get(bu);
cin.get(bu);
while(case_no--){
no=0;
while(cin.peek()!='\n'){
cin>>t_string>>t_int;
cin.get(bu);
if(cin.peek()!='\n')
cin>>t_double;
else
t_double=0.0;
if(t_double<1000000){
(table[no]).date=t_string;
(table[no]).check=t_int;
(table[no]).money=t_double;
no++;
}
cin.get(bu);
}
sort(table,table+no,new_less);
(table[0]).star=false;
for(i=1;i<no;i++)
if((table).check-(table[i-1]).check!=1)
(table).star=true;
else
(table).star=false;
if(no%3==0)
dx=no/3;
else
dx=no/3+1;
for(i=1;i<=ceil(double(no)/3.0);i++){
print(i-1,no);
cout<<" ";
print(i-1+dx,no);
cout<<" ";
print(i-1+dx*2,no);
cout<<endl;
}
if(case_no)
cout<<endl;
cin.get(bu);
}
return 0;
}
[/cpp]
You should try to use vector to handle this.
Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 426 - Fifth Bank of Swamp County
Following is the output generated by my A.C. program:boshkash1986 wrote:Please can anyone give me the correct ouput for this :
Code: Select all
5 93/10/15 1001 116.81 93/10/27 1000 840.85 93/10/26 1002 555.55 93/10/26 1003 555.55 93/10/15 1001 93/10/27 1000 9999999.99 93/10/26 1002 555.555 93/10/01 998 .65 93/10/01 999 0123.89 93/10/05 996 29.99 93/10/06 993 116.52 93/10/12 995 418.00 93/10/15 1001 15045.00 93/10/27 1000 840.85 93/10/15 1003 15045.00 93/10/01 998 .65 93/10/01 999 0123.89 93/10/05 996 29.99 93/10/06 993 116.52 93/10/12 995 418.00 93/10/15 1001 15045.00 93/10/27 1000 840.85 93/10/15 1003 15045.00 93/10/15 1006 93/10/01 998 .65 93/10/01 999 0123.89 93/10/05 996 29.99 93/10/06 993 116.52 93/10/12 995 418.00
Code: Select all
1000 840.85 93/10/27 1002 555.55 93/10/26
1001 116.81 93/10/15 1003 555.55 93/10/26
1000 9999999.99 93/10/27 1001 0.00 93/10/15 1002 555.55 93/10/26
993 116.52 93/10/06 998* 0.65 93/10/01 1001 15045.00 93/10/15
995* 418.00 93/10/12 999 123.89 93/10/01 1003* 15045.00 93/10/15
996 29.99 93/10/05 1000 840.85 93/10/27
993 116.52 93/10/06 998* 0.65 93/10/01 1001 15045.00 93/10/15
995* 418.00 93/10/12 999 123.89 93/10/01 1003* 15045.00 93/10/15
996 29.99 93/10/05 1000 840.85 93/10/27 1006* 15045.00 93/10/15
993 116.52 93/10/06 996 29.99 93/10/05 999 123.89 93/10/01
995* 418.00 93/10/12 998* 0.65 93/10/01
Have you ever...
- Wanted to work at best companies?
- Struggled with interview problems that could be solved in 15 minutes?
- Wished you could study real-world problems?