sábado, 11 de febrero de 2012

Problema 22 euler

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class problem22 
{
 public static void main(String[] args) throws FileNotFoundException 
 {
  String v[]=null;
  File a = new File("C:\\names.txt");
   Scanner sc = new Scanner(a);
   int c =1;
  while(sc.hasNext())
  {
    v= sc.next().split(",");
  }
    Arrays.sort(v);
    long f=0;
    for (int i = 0; i < v.length; i++) 
   {
     String x = v[i].substring(1, v[i].length()-1);
     int co =0;
     for (int j = 0; j < x.length(); j++) 
     {
    co= (x.charAt(j)-64)+co;
     }
     co= co*(i+1);
     f=f+co;
   }
    System.out.println(f);
 }

}

No hay comentarios:

Publicar un comentario