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 ...
随机推荐
- java 从零开始手写 RPC (03) 如何实现客户端调用服务端?
说明 java 从零开始手写 RPC (01) 基于 socket 实现 java 从零开始手写 RPC (02)-netty4 实现客户端和服务端 写完了客户端和服务端,那么如何实现客户端和服务端的 ...
- Serverless X OpenKruise 部署效率优化之道
作者 | 许成铭(竞霄) Serverless 作为云计算的最佳实践.云原生发展的方向和未来演进趋势,其核心价值在于快速交付.智能弹性.更低成本.SAE(Serverless 应用引擎)作为首款面向应 ...
- 题解 Crash 的文明世界
题目传送门 题目大意 给出一个\(n\)个点的树,和常数\(k\),对于\(\forall i\in[1,n]\),求出: \[\sum_{j=1}^{n} \text{dist}(i,j)^k \] ...
- 题解「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set
题目传送门 题目大意 给出一个长度为 \(n\) 的数组,选出一些数异或之和为 \(s1\),其余数异或之和为 \(s2\),求 \(s1+s2\) 最大时 \(s1\) 的最小值. 思路 你发现如果 ...
- Visual Studio CMake 项目和 WSL
Visual Studio CMake 项目和 WSL https://devblogs.microsoft.com/cppblog/c-with-visual-studio-2019-and-win ...
- 个人记录:对于python学习的反思和总结(一)
在写代码时,总是遇到写着写着不知道怎么写了的情况,或者无法把自己的想法用程序表达出来,所以有时候我们需要建立一个自己的编程思路,对一个具体程序的编程有一个比较清晰的想法:因此我把自己的思路总结了一下, ...
- javascript-jquery的基本方法
1.去除字符串中两端的空格$.trim(str) var str1=" 123 " $.trim(str1);//123 2.遍历对象的数据并进行操作$.each(obj,func ...
- lib库无法加载的情况分析
最近升级vs2017的时候遇到无法加载库的问题,在网上查找问题,网上给出可能有三种情况导致该问题:路径是否正确:库依赖是否齐全:库版本是否正确.最直接的方法就是用depends软件去查询,是否有模块有 ...
- Linux入门需要搞清楚的思路问题
很多同学接触linux不多,对linux平台的开发更是一无所知. 而现在的趋势越来越表明,作为一个优秀的软件开发人员,或计算机it行业从业人员,="" 掌握linux是一种很重要的 ...
- sublime text c++ makefile
http://blog.csdn.net/wangdan1600/article/details/43857195 http://blog.csdn.net/artprog/article/detai ...