10336 - Rank the Languages

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

mastergoos
New poster
Posts: 2
Joined: Tue Nov 01, 2011 9:46 pm

10336 - Rank the Languages

Post by mastergoos » Tue Nov 01, 2011 10:27 pm

I've tried so much tests, in every tests the result is correct..
The submit say: Wrong Answer.
What is wrong on my code ?

Code: Select all

import java.util.Scanner;

public class Main {

	private static char[][] grid;
	private static int[] dx = { 0, -1, 0, 1 };
	private static int[] dy = { -1, 0, 1, 0 };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = "";
		int N = Integer.parseInt(sc.nextLine());
		int map = 0;
		while (N-- > 0) {
			s = sc.nextLine();
			String[] size = s.split("\\s");
			int n = Integer.parseInt(size[0]);
			int m = Integer.parseInt(size[1]);
			grid = new char[n][m];
			for (int i = 0; i < n; ++i) {
				grid[i] = sc.nextLine().toCharArray();
			}
			char[] alph = letters();
			int[] amm = new int[alph.length];
			for (int i = 0; i < amm.length; i++) {
				for (int j = 0; j < n; j++) {
					for (int k = 0; k < m; k++) {
						if (grid[j][k] == alph[i]) {
							dfs(j, k, alph[i], Character.toUpperCase(alph[i]));
							amm[i]++;
						}
					}
				}
			}
			sort(alph, amm);
			System.out.print("World #" + (++map) + "\n");
			for (int i = 0; i < amm.length; i++) {
				System.out.print(alph[i] + ": " + amm[i] + "\n");
			}
		}
		System.exit(0);
	}

	public static char[] letters() {
		boolean[] aux = new boolean[26];
		for (int i = 0; i < grid.length; i++) {
			for (int j = 0; j < grid[0].length; j++) {
				aux[grid[i][j] - 'a'] = true;
			}
		}
		int amm = 0;
		for (boolean i : aux) {
			if (i)
				++amm;
		}
		char[] ret = new char[amm];
		amm = 0;
		for (int i = 0; i < 26; ++i) {
			if (aux[i]) {
				ret[amm++] = (char) (i + 'a');
			}
		}
		return ret;
	}

	public static void dfs(int x, int y, char cur, char rep) {
		if (grid[x][y] != cur)
			return;
		grid[x][y] = rep;
		for (int i = 0; i < 4; i++) {
			if (x + dx[i] >= 0 && y + dy[i] >= 0 && x + dx[i] < grid.length && y + dy[i] < grid[0].length && grid[x + dx[i]][y + dy[i]] == cur) {
				dfs(x + dx[i], y + dy[i], cur, rep);
			}
		}
	}

	public static void sort(char[] alph, int[] amm) {
		int n = alph.length;
		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < n - i - 1; j++) {
				if (amm[j] < amm[j + 1]) {
					char temp0 = alph[j + 1];
					alph[j + 1] = alph[j];
					alph[j] = temp0;
					int temp1 = amm[j + 1];
					amm[j + 1] = amm[j];
					amm[j] = temp1;
				}
			}
		}
	}
}

donintosh
New poster
Posts: 2
Joined: Tue Nov 22, 2011 12:37 pm

Re: 10336 - Rank the Languages

Post by donintosh » Wed Nov 23, 2011 3:14 pm

Can't find anything really...

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 10336 - Rank the Languages

Post by moudud99 » Fri Oct 03, 2014 7:55 pm

strange and funny problem....Please someone give some Inputs..

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 10336 - Rank the Languages

Post by moudud99 » Fri Oct 03, 2014 7:58 pm

here is my code I'm tired of getting WA on silly mistake..

Code: Select all

AC
Last edited by moudud99 on Sat Oct 04, 2014 12:52 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10336 - Rank the Languages

Post by brianfry713 » Sat Oct 04, 2014 12:55 am

Look at the sample output, you are missing the :
Check input and AC output for thousands of problems on uDebug!

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 10336 - Rank the Languages

Post by moudud99 » Sat Oct 04, 2014 12:53 pm

thanks a lot brainfry...I should have better ability to hack own code... :roll: :roll:

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10336 - Rank the Languages

Post by uDebug » Sat Apr 04, 2015 1:35 pm

I added some random test cases on uDebug:
http://www.udebug.com/UVa/10336
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 103 (10300-10399)”