fork download
  1. /*
  2.  Benjamin Parker
  3.  Jonathan Tolentino
  4.  CMPS 345 Term Project (Problem #4)
  5.  Arbitrage Algorithm
  6.  12/21/15
  7.  
  8.  DESCRIPTION
  9.  This program will use an implementation of the Floyd-Warshall algorithm to
  10.  determine if an arbitrage exists in a matrix of 50 currencies, starting
  11.  with USD.
  12. */
  13.  
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdlib>
  17. #include <math.h>
  18. #include <list>
  19. using namespace std;
  20.  
  21. public class CalculateTotalPrice {
  22.  
  23. public static void main(String[] args) {
  24. int[] prices= {101,30,2,80,10};
  25. System.out.println(calculateTotalPrice1(prices, 20));
  26.  
  27. }
  28.  
  29. public static int calculateTotalPrice1(int[] prices,int discount) {
  30. int total1=0;
  31. int len=prices.length;
  32. Arrays.sort(prices);
  33. for(int i=0;i<len-1;i++) {
  34. total1=total1+prices[i];
  35. }
  36. return (int) ( (total1+(float) ((prices[len-1])-((prices[len-1])*discount/100))));
  37.  
  38. }
  39. }
Success #stdin #stdout 0.03s 25472KB
stdin
Standard input is empty
stdout
/*
 Benjamin Parker
 Jonathan Tolentino
 CMPS 345 Term Project (Problem #4)
 Arbitrage Algorithm
 12/21/15

 DESCRIPTION
 This program will use an implementation of the Floyd-Warshall algorithm to
 determine if an arbitrage exists in a matrix of 50 currencies, starting
 with USD.
*/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <math.h>
#include <list>
using namespace std;

public class CalculateTotalPrice {
 
	public static void main(String[] args) {
		int[] prices= {101,30,2,80,10};
		System.out.println(calculateTotalPrice1(prices, 20));
 
	}
 
public static int calculateTotalPrice1(int[] prices,int discount) {
		int total1=0;
		int len=prices.length;
		Arrays.sort(prices);
		for(int i=0;i<len-1;i++) {
			total1=total1+prices[i];
		}
		return (int) ( (total1+(float) ((prices[len-1])-((prices[len-1])*discount/100))));
 
	}
}