Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-09-30 16:17:49100
2015-09-30 16:08:1739
2015-09-30 16:05:59
2015-09-30 16:01:3639
2015-09-30 15:57:2339
2015-09-30 15:56:2439
2015-09-30 15:54:590
2015-09-30 15:50:190
Task:Osajono
Sender:niklaskoskinen
Submission time:2015-09-30 16:05:59
Language:Java
Status:COMPILE ERROR

Compiler report

input/Test.java:12: error: incompatible types: possible lossy conversion from long to int
            num[ccnum] = num[ccnum] + 1;            
                ^
input/Test.java:12: error: incompatible types: possible lossy conversion from long to int
            num[ccnum] = num[ccnum] + 1;            
                             ^
2 errors

Code

import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        String test = inp.nextLine();
        long[] num;
        num = new long[26];
        char[] testa = test.toCharArray();
        for(char t : testa){
            long cnum = (long) t;
            long ccnum = cnum - 65;
            num[ccnum] = num[ccnum] + 1;            
        }
        long ans = 0;
        for(long n : num){
            ans = ans + ((n * (n + 1))/2);
        }
        System.out.println(ans);
        
        
        }
    }