Way too long words

This is my solution to the “way too long words” problem on codeforces. Even though I am getting correct output, but still it has been reported as the wrong answer to a question by codeforces.

https://codeforces.com/problemset/problem/71/A (link to the question)

import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        //charAt() is an inbuilt method which can read a string letter by letter
        Scanner input=new Scanner(System.in);
        int n;
        //System.out.println("how many words do you wish to enter?");
        n=input.nextInt();
        String[] words=new String[n+1];
        for(int i=0;i<n+1;i++)
        {
            words[i]=input.nextLine();
        }

        for(int j=0;j<n+1;j++)
        {
            if(words[j].length()<10)
            {
                System.out.print(words[j]);
            }

            else
            {
                System.out.print(words[j].charAt(0));
                System.out.print(words[j].length()-2);
                System.out.print(words[j].charAt(words[j].length()-1));
            }

            System.out.print("n");
        }

    }

}

Answer

Problem is with the condition, you are only skipping words below the length of 10 but not considering the words with exact of 10 length.

 if(words[j].length()<=10)
 {
        System.out.print(words[j]);
 }

Change the condition it should work.

Leave a Reply

Your email address will not be published. Required fields are marked *