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. windows下编译caffe出现错误 C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe?

    解决方案来自http://blog.csdn.net/u012556077/article/details/50353818

  2. 在Vue中使用JSX,很easy的

    摘要:JSX 是一种 Javascript 的语法扩展,JSX = Javascript + XML,即在 Javascript 里面写 XML,因为 JSX 的这个特性,所以他即具备了 Javasc ...

  3. Java初步学习——2021.10.12每日总结,第六周周二

    (1)今天做了什么: (2)明天准备做什么? (3)遇到的问题,如何解决? 今天学习了菜鸟教程Java实例,数组 1.数组的排序和元素的查找--sort和binarySearch方法 import j ...

  4. bzoj2460元素(线性基,贪心)

    题目大意: 给定\(n\)个二元组\((a,b)\),求一个最大的\(\sum b\)的集合,满足这个集合的任意子集的\(a\)的\(xor\)值不为0 这道题需要一个线性基的性质: 线性基的任何非空 ...

  5. GIS应用|快速开发REST数据服务

    随着计算机的快速发展,GIS已经在各大领域得到应用,和我们的生活息息相关, 但是基于GIS几大厂商搭建服务,都会有一定的门槛,尤其是需要server,成本高,难度大,这里介绍一种在线GIS云平台,帮你 ...

  6. flask 之 请求钩子

    请求钩子 什么是请求钩子? 在客户端和服务器交互的过程中,有些准备工作或扫尾工作需要统一处理,为了让每个视图函数避免编写重复功能的代码,flask提供了统一的接口可以添加这些处理函数,即请求钩子. f ...

  7. spring提供的可拓展接口

    接口:SmartLifecycle(https://www.jianshu.com/p/7b8f2a97c8f5)

  8. 使用寄存器点亮LED——2

    1. 项目:使用stm32寄存器点亮LED, 分别点亮红.绿.蓝3个灯. 2. 步骤 先新建个文件夹保存项目 再新建项目 将startup_stm32f10x_hd.s拷贝到该文件夹下 新建main. ...

  9. 项目优化之v-if

    前言: 在vue项目中,由于功能比较多,需要各种条件控制某个功能.某个标签.表格中的某一行是否显示等,需要使用大量的v-if来判断条件. 例如: <div v-if="isShow(a ...

  10. $dy$讲课总结

    字符串: 1.广义后缀自动机(大小为\(m\))上跑一个长度为\(n\)的串,所有匹配位置及在\(parent\)树上其祖先的数量的和为\(min(n^2,m)\),单次最劣是\(O(m)\). 但是 ...