Financial Tsunami
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的更多相关文章
- 即将翻译 Building The New Financial Times Web App
<金融时报>这份Web APP 经验的总结,写得非常详细,也提到Web APP制作中常遇到的问题.为么他们就没有点透Bug - -! Building The New Financial ...
- Divide and conquer:Moo University - Financial Aid(POJ 2010)
Moo University - Financial Aid 其实是老题了http://www.cnblogs.com/Philip-Tell-Truth/p/4926008.html 这一次我们换二 ...
- poj 1004:Financial Management(水题,求平均数)
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126087 Accepted: ...
- Financial Management[POJ1004]
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 179458 Accepted: ...
- 练习英语ing——[POJ1004]Financial Management
[POJ1004]Financial Management 试题描述 Larry graduated this year and finally has a job. He's making a lo ...
- Moo University - Financial Aid
Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6020 Accep ...
- Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 164431 Accepted: ...
- 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 ...
- Introduction to Financial Management
Recently,i am learning some useful things about financial management by reading <Essentials of Co ...
随机推荐
- mysql8.0.20安装教程,mysql下载安装教程8.0.20
mysql8.0.20下载安装教程 mysql8.0.20安装教程 mysql安装包+mysql学习视频+mysql面试指南视频教程 下载地址: 链接:https://pan.baidu.com/s ...
- Dapr逐渐被点燃
Dapr被点燃 Dapr的热度个人认为才刚刚热起来,9月份我写了Dapr + .NET Core实战一共10篇,从基础概念到简单的实战,但是有很多人感兴趣,具体表现在我个人维护的QQ群,人数从80人左 ...
- 12. 亿级流量电商系统JVM模型参数二次优化
亿级流量电商系统JVM模型参数预估方案,在原来的基础上采用ParNew+CMS垃圾收集器 一.亿级流量分析及jvm参数设置 1. 需求分析 大促在即,拥有亿级流量的电商平台开发了一个订单系统,我们应该 ...
- 【UE4 C++】Print、Delay、ConsoleCommand
基于UKismetSystemLibrary PrintString /** * Prints a string to the log, and optionally, to the screen * ...
- 【c++ Prime 学习笔记】第1章 开始
1.1 编写一个简单的程序 int main() { return 0; } 函数 包含4部分: 返回类型(return type) 函数名(function name) 形参列表(parameter ...
- JAVA复习总体大纲
1 java基础. [1].变量--- 数据类型 变量名=值; 数据类型: 1.基本数据类型. byte[1字节] short[2字节] int[4字节] long[8字节] float[4字节] d ...
- 敏捷 Scrum Master 的難點
什麼是 Scrum Master? Scrum master 是一個團隊角色,負責確保團隊遵守敏捷方法和原則並符合團隊的流程和實踐. Scrum Master 促進敏捷開發團隊成員之間的協作.Scru ...
- Java RMI学习与解读(一)
Java RMI学习与解读(一) 写在前面 本文记录在心情美丽的一个晚上. 嗯.就是心情很美丽. 那为什么晚上还要学习呢? emm... 卷... 卷起来. 全文基本都是根据su18师傅和其他师傅的文 ...
- JVM:体系结构
JVM:体系结构 本笔记是根据bilibili上 尚硅谷 的课程 Java大厂面试题第二季 而做的笔记 概览 Java GC 主要回收的是 方法区 和 堆 中的内容 类加载器 类加载器是什么 双亲委派 ...
- elasticsearch的bulk(批量)操作
在es中我们可能会有这么一种需求,即有时需要批量向es中插入或更新或删除数据,如果一条一条数据的操作,那么速度必然很慢,那么es的bulk api就可以派上用场. delete 删除操作,只需要写一个 ...