UVa Problem 12403 - Save Setu
Time limit: 1.000 seconds
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=3834
Rahaduzzaman Setu, (Roll - 12) of 13th batch, CSE, University of Dhaka is tremendously ill. He has
been suffering from Multi Drug Resistant TB for a long time. Now, his left lung is damaged and
beyond repair. No medicine is working on his body to ease his pain. It is urgent to operate on his left
lung so that the disease doesn’t spread to his right lung. It can either be removed through surgery
or transplanted. He comes from a modest family and it is difficult and impossible for them to bare
his medical expenses anymore. Because of the money needed (12 million BDT) to transplant, it is his
family’s decision to go with the surgery (3 million BDT). We must help them financially by raising
money. But we must not be confined with that amount only to do the surgery. We must go for the
Transplant. Our target will be to collect as much as possible to help our friend.
If anyone wants to contribute now, please send me your contribution or contact me. Please contribute
as much as you can to save a life that you saw every week for the first two years of your University life.
Please contribute as per your abilities. Our combined effort may save a life.
For more information, consult the link below.
http://supportsetu.com/
However, in this problem, you have to build a software that can calculate the donations. Initially
the total amount of money is 0 and in each time, two types of operations will be there.
1) ‘donate K’ (100 ≤ K ≤ 105
), then you have to add K to the account.
2) ‘report’, report all the money currently in the account.
Input
The first line of input will contain T (1 ≤ T ≤ 100) denoting the number of operations. Then there will
be T lines each containing two types of operations as given. You may assume that the input follows
the restrictions above.
Output
For each ‘report’ operation, print the total amount of money in the account.
Sample Input
4
donate
1000
report
donate
500
report
Sample Output
1000
1500
解題方法: 當 operation 是 donate 將輸字加總, report 就將將總的數字print 出來
import java.util.Scanner; class UvA12403 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int donations = 0 ; int n = scan.nextInt(); //insert the numbers of operations for(int i = 0 ; i < n ; i ++) { String operations = scan.next(); if(operations.equals("donate")) donations += scan.nextInt(); else System.out.println(donations); } } }