puzzle
BAN USERMy solution in Java:
public class Phone2Text {
static String[] texts = {"0", "1", "ABC", "DEF", "GHI",
"JKL", "MNO", "PQRS", "TUV", "WXYZ" };
static void word(int[] phone, int start, char[] result) {
if (start == phone.length) {
for (int i = 0; i < start; i++)
if (result[i] != '0' && result[i] != '1')
System.out.print(result[i] + " ");
System.out.println();
return;
}
for (int i = 0; i < texts[phone[start]].length(); i++) {
result[start] = texts[phone[start]].charAt(i);
word(phone, start+1, result);
}
}
public static void main(String[] args) {
int[] phone = {7, 6, 3, 4, 9, 4, 6, 2, 7, 1};
char[] result = new char[phone.length];
word(phone, 0, result);
}
}
Just use gcc -S to generate assembly code for ++a and a++ on Red Hat Linux. I found the generated the same assembly instruction. So, I think it is compiler dependent, which one is faster because on my Linux machine, it is the same.
- puzzle October 18, 2009