Ledger Nano X - The secure hardware wallet
SHARE
TWEET

HW3 - USE THIS AS BACKUP

a guest Apr 3rd, 2020 201 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2.  
  3. public class Gauntlet {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int numAvengers = sc.nextInt(); // this stores the value of N
  8.         int numRounds = sc.nextInt(); // this store the value of K
  9.         sc.nextLine(); // blank line to flush the output stream
  10.         String cmds = sc.nextLine(); // read list of commands, store in a String
  11.         String[] cmdList = cmds.split(" "); // Splitting the commands and storing each command in an array.
  12.         int i;
  13.        
  14.         //Declares Stack
  15.         Stack<Integer> commandStack = new Stack<Integer>();
  16.         int currentAvenger = 0;
  17.        
  18.         long start = System.currentTimeMillis(); // start measuring runtime.
  19.         //for (i = 0; i < numRounds; i++) {
  20.             //Loop through cmdList
  21.             for (int j = 0; j <= cmdList.length - 1; j++) {
  22.                 //Evaluate command to add or subtract from Stack
  23.                 if(cmdList[j].equals("undo")) {
  24.                     commandStack.remove(0);
  25.                 }
  26.                 else {
  27.                     //Converts string to integer and adds to the Stack
  28.                     commandStack.add(0, Integer.valueOf(cmdList[j]));
  29.                 }
  30.                 int sum = 0;
  31.                 //Sum each element in Stack
  32.                 for(i = 0; i < commandStack.size(); i++){
  33.                     sum = sum + commandStack.get(i);
  34.                 }
  35.                 currentAvenger = sum % numAvengers;
  36.                 //System.out.println("Current Avenger " + currentAvenger);
  37.             }
  38.             // your code goes here.
  39.             // This loop should iterate over the cmdList
  40.             // and determine who gets the gauntlet after each command
  41.             // all operations inside this loop should take constant time.
  42.         //}
  43.        
  44. //      //Declares sum
  45. //      int sum = 0;
  46. //      //Sum each element in Stack
  47. //      for(i = 0; i < commandStack.size(); i++){
  48. //          sum = sum + commandStack.get(i);
  49. //      }
  50.        
  51.         //Gets specific end Avenger from Mod
  52. //      int currentAvenger = sum % numAvengers;
  53.         System.out.println("The Gauntlet is with Avenger " + currentAvenger);
  54.  
  55.         long end = System.currentTimeMillis(); // stop measuring time
  56.        
  57.         System.out.println("Running time " + (end - start) + "ms"); // this will print the running time of your loop.
  58.        
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top