187 - Transaction Processing

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

Moderator: Board moderators

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath » Wed Jan 02, 2002 5:30 pm

I sent and fixed many times,but I still got wrong answer.
Can you guys tell me some common problem??Thanks.

<font size=-1>[ This Message was edited by: FlyDeath on 2002-01-02 16:30 ]</font>

Archangel
New poster
Posts: 29
Joined: Wed Jun 26, 2002 9:00 am

187 - Transaction Processing

Post by Archangel » Fri Jul 19, 2002 6:33 pm

Can anybody help me why I always got Runtime Error(signal 11 (SIGSEGV) Invalid memory reference)? :cry:

Code: Select all

#include<iostream.h>
#include<string.h>

typedef struct /* structure for transaction */
{
	char  accountnum[3]; /* transaction account */
	float money;		 /* transaction charge */
}transac;

typedef struct /* structure for account data */
{
	char  num[3]; /* account number */
	char  name[30]; /* account name (the last element store the name length) */
	short len;
}account;

char    cursor;
account data[101]; 
char    snum[3],prenum[3];
transac transaction[11];
float   result,temp;
short   index,i,j,k,len;


void main(void)
{
	index = 0;
	while(1) /* process the account data */
	{
		for (i=0;i<3;i++) /* read in account number */
		{
			cin>>data[index].num[i];
		}		
		if ((data[index].num[0] == '0')&&(data[index].num[1] == '0')&&(data[index].num[2] == '0')) /* end of account number */
			break; 
		cin.get(cursor); /* get the account name */
		for (i=0;i<30;i++)
		{
			data[index].name[i] = cursor;		
			cin.get(cursor);
			if (cursor == 10)
			{
				i++;
				break;
			}
		}
		data[index].len = i; /* store name length */
		index++; /* update the index */
	}	
	len = index;	
	cin.get(cursor); /* skip the No such accout */
	while (cursor != 10) /* move cursor the end of line */
		cin.get(cursor);
	index  = 0;
	result = 0;
	cout.setf(ios::fixed);
	cout.precision(2);
	while(1) /* process the transaction */
	{
		for (i=0;i<3;i++) /* read in sequential number */
			cin>>snum[i];
		if ((strcmp(snum,prenum) != 0)&&(index > 0)) /* when sequential number change, do print result */
		{
			if (result != 0)
			{
				cout<<"*** Transaction "<<prenum[0]<<prenum[1]<<prenum[2]<<" is out of balance ***\n"; /* print title */
				for (i=0;i<index;i++) 
				{
					for (j=0;j<3;j++) /* print account nnumber */
						cout<<transaction[i].accountnum[j];
					for (k=0;k<len;k++) /* check account */ 
					{
						if (transaction[i].accountnum[0] == data[k].num[0])
						{
							if (transaction[i].accountnum[1] == data[k].num[1])
							{
								if (transaction[i].accountnum[2] == data[k].num[2])
									break;
							}
						}
					}
					cout<<" ";
					for (j=0;j<data[k].len;j++) /* print account name */
						cout<<data[k].name[j];
					for (j=data[k].len;j<32;j++)
						cout<<" ";
					cout.width(9);
					if (transaction[i].money < 0)
						temp = 0 - ((0 - transaction[i].money) / 100);
					else
						temp = (transaction[i].money / 100);
					cout<<temp<<endl;
				} /* end for */	
				if (result > 0) /* print out of balance */
					result = 0 - (result / 100);
				else
					result = (0 - result) / 100;
				cout<<"999 Out of Balance                  ";
				cout.width(9);
				cout<<result<<endl<<endl;       
			} /* end if */
			result = 0; /* reset the state */
			index  = 0;		
		} /* end if */
		if ((snum[0] == '0')&&(snum[1] == '0')&&(snum[2] == '0')) /* end of transactions */
			break;
		strcpy(prenum,snum); /* update sequential number */
		for (i=0;i<3;i++) /* read in the account number */
			cin>>transaction[index].accountnum[i];	
		cin>>transaction[index].money; /* read in the transaction money */
		result = result + transaction[index].money;
		index++;
	}	
}

zbogi
New poster
Posts: 15
Joined: Thu Aug 29, 2002 11:00 pm
Location: Bulgaria

I have the same problem

Post by zbogi » Thu Aug 29, 2002 11:11 pm

It is not much, but atleast you know you are not alone. If I accept it or receive some other information I will write. :roll:
Tsvetan Bogdanov.
from Brain Explorer - Sofia University - FMI 2
e-mail: zbogi@yahoo.com

zbogi
New poster
Posts: 15
Joined: Thu Aug 29, 2002 11:00 pm
Location: Bulgaria

finaly got Accepted

Post by zbogi » Sun Sep 01, 2002 6:38 pm

My problem was when dividing by 100. I solved it by dividing not by 100.0, but using integer division by 100 and %100 :lol:
Tsvetan Bogdanov.
from Brain Explorer - Sofia University - FMI 2
e-mail: zbogi@yahoo.com

topraj
New poster
Posts: 5
Joined: Sat May 17, 2003 9:55 pm

187 submission

Post by topraj » Sun Aug 10, 2003 5:13 am

this problem is just too easy..
the only catch is the problemsetters forgot to mention that transactions to be debit and credit need not be 1 and 1 transactions only.
e.g.
101121 105
101241 -5
101401 -100
this would mean, 1 debit, and 2 credits cancel it out. The transactions for debit and corresponding credit aren't scattered anywhere, but follow each other,
e.g
101121 105
101151 12
101241 -5
101401 -100
here, lines 1, 3, and 4 don't cancel out.
pretty dumb... it's just a badly worded problem hence i guess some people failed.

bpytlik
New poster
Posts: 3
Joined: Tue Feb 03, 2004 6:40 pm
Location: Czech Republic
Contact:

problem 187 in java - WA

Post by bpytlik » Tue Feb 03, 2004 6:54 pm

Hi, i always receive wrong answer with my code. Where is the problem please (in my opinion it works good)???
[java]
import java.io.IOException;
import java.text.*;
import java.util.*;

class Main {
static Ucet[] ucet = new Ucet[101];
static Transakce[] transakce = new Transakce[1001];

static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}

public static void main(String[] args) {
String s;
DecimalFormat df = new DecimalFormat("0.00", new DecimalFormatSymbols(Locale.UK));
int maxUcet = 0, maxTransakce = 0;
for (int i = 0 ; i < 101 ; i++) {
s = ReadLn(34);
ucet = new Ucet(s);
maxUcet++;
if (ucet.cislo.equals("000")) break;
}
for (int i = 0 ; i < 1001 ; i++) {
s = ReadLn(16);
transakce = new Transakce(s);
if (transakce.cislo.equals("000") && transakce.ucet.equals("000"))
break;
maxTransakce++;
}
int ii = 0;
while (ii < maxTransakce) {
String testuj = transakce[ii].cislo;
int i = ii;
float castka = 0;
for ( ; testuj.equals(transakce.cislo) ; i++) castka += transakce.castka;
if (castka != 0) {
System.out.println("*** Transaction " + transakce[i-1].cislo + " is out of balance ***");
for (int j = ii ; testuj.equals(transakce[j].cislo) ; j++) {
System.out.print(transakce[j].ucet + " ");
for (int k = 0 ; k < 100 ; k++) {
if (ucet[k].cislo.equals(transakce[j].ucet)) {
System.out.print(ucet[k].nazev);
for (int f = 0 ; f < (30 - ucet[k].nazev.length()) ; f++)
System.out.print(" ");
for (int f = 0 ; f < (10 - new Float((df.format(transakce[j].castka))).toString().length()) ; f++)
System.out.print(" ");
System.out.println(df.format(transakce[j].castka));
break;
}
}
}
System.out.print("999 Out of Balance ");
for (int f = 0 ; f < (10 - new Float((df.format(0-castka))).toString().length()) ; f++)
System.out.print(" ");
System.out.println(df.format(0-castka));
System.out.println("");
}
ii = i;
}
}
}

class Ucet {
String cislo;
String nazev;

Ucet(String s) {
cislo = s.substring(0,3);
nazev = s.substring(3,s.length()-1);
}
}

class Transakce {
String cislo;
String ucet;
float castka;

Transakce(String s) {
boolean znamenko = false;
cislo = s.substring(0,3);
ucet = s.substring(3,6);
s = s.substring(7,s.length()).trim();
if ("-".equals(s.substring(0,1))) {
znamenko = true;
s = s.substring(1, s.length());
}
int length = s.length();
if (length == 2) {
if (znamenko) s = "-0." + s;
else s = "0." + s;
}
else if (length == 1) {
if (znamenko) s = "-0.0" + s;
else s = "0.0" + s;
}
else {
if (znamenko) s = "-" + s.substring(0,length-2) + "." + s.substring(length-2,length);
else s = s.substring(0,length-2) + "." + s.substring(length-2,length);
}
castka = (new Float(s)).floatValue();
}
}
[/java]

Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
Location: Edmonton AB Canada

Post by Quantris » Mon May 16, 2005 3:05 am

From the problem statement:

Each of these records is one entry of a transaction. A transaction consists of between two and ten entries with identical sequence numbers. Each transaction will be contiguous within the input data.

I don't think that it is "badly worded" at all - it might be a bit confusing though. All you have to check is if each transaction balances (as a whole) - there is no suggestion that it has to be one credit to one debit.

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR » Tue May 17, 2005 7:52 am

Quantris,

as far as I remember that's problem 187 you're describing (I've solved that already).

Any ideas as to 186?

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

187

Post by emotional blind » Sat Dec 10, 2005 6:46 am

what should be the output of this input

Code: Select all

111Cash 
121Accounts Receivable
211Accounts Payable
241Sales Tax Payable 
401Sales
555Office Supplies
000No such account
100111100000000
100121-50000000
100134-50000001
101121      105
101241       -7 
101401     -100
102211   -70000
102555    40000
103111   -40000 
103555    40000
000000        0
I alwas get WA why
here is my code in C++

Code: Select all

ACCEPTED after two years
any idea plz help me
Last edited by emotional blind on Tue Jun 19, 2007 8:15 am, edited 1 time in total.

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Fri Dec 23, 2005 3:00 pm

no one can help me with the output?
for the input set i have already sent

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon » Thu Jan 05, 2006 12:10 am

Hi,

My AC code outputs:

Code: Select all

*** Transaction 100 is out of balance ***
111 Cash                           1000000.00
121 Accounts Receivable            -500000.00
134 -500000.01
999 Out of Balance                       0.01

*** Transaction 101 is out of balance ***
121 Accounts Receivable                  1.05
241 Sales Tax Payable                   -0.07
401 Sales                               -1.00
999 Out of Balance                       0.02

*** Transaction 102 is out of balance ***
211 Accounts Payable                  -700.00
555 Office Supplies                    400.00
999 Out of Balance                     300.00


Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

I getting P.E in 187

Post by Mushfiqur Rahman » Sat Mar 10, 2007 4:58 am

I am getting P.E. How can I remove this? Anybody help please.

Here's my code:

Code: Select all

Removed After ACC
Last edited by Mushfiqur Rahman on Mon Mar 12, 2007 12:37 pm, edited 1 time in total.

User avatar
Rupak
New poster
Posts: 8
Joined: Mon Jan 15, 2007 6:53 am
Location: Bangladesh

Post by Rupak » Mon Mar 12, 2007 9:22 am

Mushfiq , you have the problem with fieldwitdh for the value (ara[k].value/100.00) and fabs(sum/100.00) .

Fixed it and got ACC .
_______________________________________
http://acm.uva.es/problemset/usersnew.php?user=6114

Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

Post by Mushfiqur Rahman » Mon Mar 12, 2007 12:25 pm

Rupak said,
Mushfiq , you have the problem with fieldwitdh for the value (ara[k].value/100.00) and fabs(sum/100.00) .

Fixed it and got ACC .
Can u tell me how can I fix that problem.

Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

Post by Mushfiqur Rahman » Mon Mar 12, 2007 12:36 pm

Now I got ACC. The problem was in my field witdth. It would be %10.2lf

Post Reply

Return to “Volume 1 (100-199)”