COP 3502: PROGRAMMING ASSIGNMENT 4

DUE DATE: MARCH 16, 4:00 PM

Name your class as PA4 and turn in .java file through Sakai. (20 points)

Financial Tsunami

Banks lend money to each other. In tough economic times, if a bank goes bankrupt, it may not be able to pay back the loan (You might remember 2008 banking crisis).

A bank’s total assets are its current balance plus its loans to other banks. Figure 1 is a diagram that shows five banks. The banks’ current balances are 25, 125, 175, 75, and 181 million dollars, respectively. The directed edge from node 1 to node 2 indicates that bank 1 lends 40 million dollars to bank 2.

Figure 1 Banks lend money to each other.

If a bank’s total assets are under a certain limit, the bank is unsafe. The money it borrowed cannot be returned to the lender, and the lender cannot count the loan in its total assets. Consequently, the lender may also be unsafe, if its total assets are under the limit.

Write a program to find all unsafe banks. Your program reads the input as follows. It first reads two integers nand limit, where n indicates the number of banks and limit the minimum total assets for keeping a bank safe. It then reads n lines that describe the information for n banks with id from 0 to n-1. The first number in the line is the bank’s balance, the second number indicates the number of banks that borrowed money from the bank, and the rest are pairs of two numbers. Each pair describes a borrower. The first number in the pair is the borrower’s id and the second is the amount borrowed. For example, the input for the five banks in Figure 1 is as follows (note that the limit is 201):

>5 201

>25 2 1 100.5 4 320.5

>125 2 2 40 3 85

>175 2 0 125 3 75

>75 1 0 125  >181 1 2 125

The  total  assets  of  bank  3  are  (75 + 125 = balance + loan),  which  is  under

201.  So bank 3 is unsafe. After bank 3 becomes unsafe, the total assets of bank 1 will fall below (125 + 40). So, bank 1 is also unsafe. The output of the program should be

>Unsafe banks are 3 1

(Hint:   Use   a   two-dimensional   array   borrowers to   represent   loans. borrowers[i][j] indicates the loan that bank i loans to bank j. Once bank j becomes unsafe, borrowers[i][j] should be set to 0.)

import java.util.Scanner;

public class J717
{
public static void main (String[] args){
Scanner scan = new Scanner (System.in);
int banks = scan.nextInt();
double[] b = new double[banks];
double[][] borrowsers = new double[5][5];
int limit = scan.nextInt();
for (int i =0;i<b.length;i++){
b[i] = scan.nextDouble();
int howmany = scan.nextInt();
for (int j =0;j<howmany;j++){
borrowsers[i][scan.nextInt()] = scan.nextDouble();
}
}
for (int j =0;j<banks;j++){
for (int k =0; k<banks;k++){
int total =0;
//Calculating total number of loans given by k
for (int l =0;l<banks;l++){
total +=borrowsers[k][l];
}
if (total + b[k] < limit){
for (int m =0;m<banks;m++){
borrowsers[m][k] = 0;
}
}
}
}
System.out.print("Unsafe banks are ");
for (int k =0; k<banks;k++)
{
int total =0;
//Calculating total number of loans made by k
for (int l =0;l<banks;l++)
{
total +=borrowsers[k][l];
}
if (total + b[k] < limit)
{
System.out.print(k + " ");
}
scan.close();
}
}
}

Financial Tsunami的更多相关文章

  1. 即将翻译 Building The New Financial Times Web App

    <金融时报>这份Web APP 经验的总结,写得非常详细,也提到Web APP制作中常遇到的问题.为么他们就没有点透Bug - -! Building The New Financial ...

  2. Divide and conquer:Moo University - Financial Aid(POJ 2010)

    Moo University - Financial Aid 其实是老题了http://www.cnblogs.com/Philip-Tell-Truth/p/4926008.html 这一次我们换二 ...

  3. poj 1004:Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

  4. Financial Management[POJ1004]

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 179458   Accepted: ...

  5. 练习英语ing——[POJ1004]Financial Management

    [POJ1004]Financial Management 试题描述 Larry graduated this year and finally has a job. He's making a lo ...

  6. Moo University - Financial Aid

    Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6020 Accep ...

  7. Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 164431   Accepted: ...

  8. How to get Financial Dimension Value from Worker Position[AX2012]

    To get financial dimension value from worker position, add a new method in hcmWorker Table with scri ...

  9. Introduction to Financial Management

    Recently,i am learning some useful things about financial management by reading <Essentials of Co ...

随机推荐

  1. Apache Struts2 S2-013远程代码执行漏洞复现

    墨者学院开的靶场 进入环境 Struts2-013好家伙,框架直接写脸上,怕人看不出来= = 看了看源码什么的啥都没发现= = 去了解了一下这个漏洞,爬回来继续做 漏洞原理 struts2的标签中&l ...

  2. T-SQL——函数——字符串操作函数

    目录 0. 加号(+) 1. LEFT和RIGHT 2. SUBSTRING 3. LEN和DATALENGTH 4. CHARINDEX和PATINDEX 5. REPLACE 6. REPLICA ...

  3. Android系统编程入门系列之应用间数据共享ContentProvider

    内容提供者ContentProvider与前文的界面Activity.服务Service.广播接收者BroadcastReveiver,并列称为Android的四大组件,均是需要自定义子类继承上述组件 ...

  4. C#开发BIMFACE系列50 Web网页中使用jQuery加载模型与图纸

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在前一篇博客<C#开发BIMFACE系列49 Web网页集成BIMFACE应用的技术方案>中介绍了目前市场主流 ...

  5. 一个简单的单例模式Demo

    /** * @author :nx014924 * @date :Created in 5/30/2021 1:09 PM * @description: * @modified By: * @ver ...

  6. Sequence Model-week1编程题1(一步步实现RNN与LSTM)

    一步步搭建循环神经网络 将在numpy中实现一个循环神经网络 Recurrent Neural Networks (RNN) are very effective for Natural Langua ...

  7. Golang通脉之反射

    什么是反射 官方关于反射定义: Reflection in computing is the ability of a program to examine its own structure, pa ...

  8. OO课第三单元总结

    一.梳理JML语言的理论基础 (1)理论基础 JMl的出现很大程度上一为了行为接口的规范化,用这种语言来指定特定模块的特定功能.JML的核心部分分为三个部分:前置条件(requires).后置条件(e ...

  9. spring security中ajax超时处理

    spring security为我们的系统提供了方便的认证和授权操作.在系统中完成认证和授权后,一般页面页面上大多数是ajax和后台进行操作,那么这个时候可能就会面临session超时,ajax去访问 ...

  10. Noip模拟29(瞎眼忌) 2021.8.3

    T1 最长不下降子序列 在此记录自己的瞎眼... 考场上像一个傻$der$,自己为了防范上升序列和不下降序列的不同特意的造了一组$hack$数据来卡自己:(第一行是序列长度,第二行是序列) 6 1 5 ...