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 ...
随机推荐
- nginx禁止IP访问系统
server { listen 80 default; server_name _; if ($host ~ "\d+\.\d+\.\d+\.\d") { return 404; ...
- 前端必会的Javascript经典面试题
这是前端最基础的问题,也是在面试中难倒无数同学的经典问题 01. Javascript 数据类型 Javascript 数据类型 = 基本类型 + 引用类型 ES6 之前 5 + 1 = 6 种 ES ...
- vue 动态菜单以及动态路由加载、刷新采的坑
需求: 从接口动态获取子菜单数据 动态加载 要求只有展开才加载子菜单数据 支持刷新,页面显示正常 思路: 一开始比较乱,思路很多.想了很多 首先路由和菜单共用一个全局route, 数据的传递也是通过s ...
- NX7.5 使用UF_MODL_create_proj_curves创建投影曲线
1 [DllImport("libufun.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet ...
- Convolutional Neural Network-week2编程题2(Residual Networks)
1. Residual Networks(残差网络) 残差网络 就是为了解决深网络的难以训练的问题的. In this assignment, you will: Implement the basi ...
- 热身 for computer industry
项目 内容 作业属于 班级博客 作业要求 作业要求 个人课程目标 掌握软件工程基础知识 具体有助方面 个人认知与规划 其他参考文献 博客Ⅰ 博客 Ⅱ 选择计算机 你为什么选择计算机专业?你认为你的条件 ...
- 零基础入门C语言超详细的字符串详解
本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, ...
- VCS常用仿真选项开关及步骤总结
转自:https://blog.csdn.net/bcs_01/article/details/79803304 转自:https://blog.csdn.net/wonder_coole/artic ...
- 在c中使用正则表达式
今天学习编译原理的时候,用c写一个简易的文法识别器实验遇到了一个问题:要用正则表达式去识别正则文法里面的A->ω,A->Bω, 其中ω属于T的正闭包,也就是说我们对正则文法的产生式进行抽象 ...
- Ubuntu Python2 和 Python3 共存 切换
例如 你写了代码 创建一个文件 在终端 vim test.py 然后写入代码 print "hello world" 接着运行代码 python test.py 会输出 hello ...