Bank statement

ABC Bank’s customer Aaron downloads his Savings account’s transaction ledger for R days which has R rows in the following format:

<credit / debit>

The transaction id is a sequential number From 1 to R, and the initial balance (before the first day) in Aaron’s account is zero

The ledger is sorted by date and spans over a period of R days. The last date in the ledger provides Aaron with the total savings account interest accrued over the year, at the daily rate of A% per annum (taken to be 365 days). This also shows in the remark field as “Interest for R days”. Interest is calculated on a daily basis and is not credited back to the balance.

Aaron notices that two consecutive rows in the ledger are fully corrupted and despite repeated downloads he cannot get proper data for these two rows. These are two rows outside of the last row which is labeled “Interest for R days”. The two corrupted rows are represented by gaps in the id numbers.

Write a program to help Aaron to find the value of the two corrupted rows i.e. <credit / debit>

Constraints

0 < amount < 1000

5 < R < 365

Input Format

The first line contains a decimal A which denotes the rate of interest per annum (expressed as a percentage). A year is taken as 365 days.

The second line contains an integer R that denotes the total number of rows that should have been there in the Account Statement.

The next (R-2) lines contain the transaction details of the format <credit / debit> delimited by a single space character where

  1. - An integer that represents the transaction id

  2. - An integer that represents the amount transacted

  3. <credit / debit> - Represents the type of transactions i.e. either credit or debit

  4. - An integer that represents balance in account after the transaction has completed

The last line contains a high precision decimal number that denotes the total sum of interest earned at the end of the last day of transaction.

Output

2 lines containing the corrupted transaction details in the format:

<credit / debit>

Where Amount and Balance are numbers rounded to the nearest integer.

Test Case

Explanation

Example 1

Input

8.0

10

1 355 credit 355

2 202 debit 153

3 59 debit 94

4 31 debit 63

7 355 debit 261

8 253 credit 514

9 308 debit 206

10 69 debit 137

0.6084383561643835

Output

5 314 credit 377

6 239 credit 616

Explanation

A=8 (the interest rate is 8% per annum)

R is 10 (10 days)

The rate of Interest is 8% per annum. In 10 days Aaron generated interest of 0.6084383561643835.

Since, rows 5 and 6 do not appear in the input, consider them as corrupted. Upon calculation the corrupted rows are as shown in the output.

i can explain if u want this is my code…enjoyyy

#include
#include
#include
using namespace std;
int main(){
int n,m,r,id[1000],amount[1000],bal[1000],pos;
double bal1,bal2,amt1,amt2;
string type[1000],type1,type2;
double intr,totalin,sum=0;
cin>>intr;
cin>>r;
for(int i=0;i<r-2;i++){
cin>>id[i]>>amount[i]>>type[i]>>bal[i];
sum+=bal[i];
}
cin>>totalin;

for(int i=0;i<r-3;i++){//cout<<id[i];
	if(id[i]!=id[i+1]-1)
		{
			pos=i+1;
			break;
		}

}
//cout<<sum<<" ";
if(type[pos]=="credit")
{
	sum+=bal[pos]-amount[pos];
	bal2=bal[pos]-amount[pos];
}
else{
	sum+=bal[pos]+amount[pos];
	bal2=bal[pos]+amount[pos];
}
//cout<<bal[pos-1]<<" "<<bal1<<endl;

 bal1=((totalin*100)*(365/(double)intr))-(double)sum;
 if(bal1>bal[pos-1]){
	type1="credit";//cout<<"x";
	amt1=bal1-bal[pos-1];
}
else{
 type1="debit";
 amt1=bal[pos-1]-bal1;
}

if(bal2>bal1){
	type2="credit";
	amt2=bal2-bal1;
}
else {
	type2="debit";
	amt2=bal1-bal2;
}
cout<<pos+1<<" "<<amt1<<" "<<type1<<" "<<round(bal1)<<endl;

cout<<pos+2<<" "<<amt2<<" "<<type2<<" "<<round(bal2)<<endl;

}

1 Like

this will not work if the missing lines have id 1,2 or r,r-1 ;