Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by capncoolio ( 15 years ago )
import java.util.*;

public class PercentStoc {

 public static void getData() {
  Scanner scan = new Scanner(System.in);
  int point = 0, amount = 0, currentPos = -1;
  String in, product = "";
  boolean alreadyExists = false;
  String[] productTable = new String[10];
  int[] amountTable = new int[10];

  while(scan.hasNext()) {
   in = scan.nextLine();
   for(int i = 0; i < in.length(); i++) {
    if(in.charAt(i) == ' ')
     point = i;
   }
   product = in.substring(0, (point));
   amount = Integer.parseInt(in.substring((point + 1)));
   //System.out.println("The product: " + product);
   //System.out.println("The amount: " + amount);
   for(int i = 0; i < 10; i++) {
    if(product.equals(productTable[i])) {
     amountTable[i] += amount;
     alreadyExists = true;
    }
   }
   if(!alreadyExists) {
    productTable[currentPos + 1] = product;
    amountTable[currentPos + 1] = amount;
    currentPos++;
   } else {
    alreadyExists = false;
   }
   //System.out.println("CPOS: " + currentPos);
   //System.out.println("The product: " + productTable[currentPos]);
   //System.out.println("The amount total: " + amountTable[currentPos]);
  }
 }
 public static void main (String[] args) {
  getData();
 }
}

 

Revise this Paste

Your Name: Code Language: