Pages

Saturday 13 July 2013

UVA - 12602 - Nice Licence Plates

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int cases=Integer.parseInt(br.readLine());
        for(int i=0;i<cases;i++){
            String str=br.readLine();
            int n1=(str.charAt(0)-'A')*26*26;
            n1+=(str.charAt(1)-'A')*26;
            n1+=(str.charAt(2)-'A');
            int n2=(str.charAt(4)-'0')*1000;
            n2+=(str.charAt(5)-'0')*100;
            n2+=(str.charAt(6)-'0')*10;
            n2+=(str.charAt(7)-'0');
            if(Math.abs(n1-n2)>100){
                sb.append("not nice\n");
            }else{
                sb.append("nice\n");
            }
        }
        System.out.print(sb);
    }

}

2 comments:

  1. Hi,

    I've been stuck in trying to solve uva 1591 the dictionary size.

    http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=4265

    Could you give me a hint of the data structure you used? Thanks!

    ReplyDelete
    Replies
    1. Trying thinking about a simple a Linked List .. and simple counters ..

      Delete