## Questions d'entretien

Entretien pour Software Engineer Intern

-

# Suppose we can translate numbers into characters: 1->a, 2->b, ...26->z given an integer, for example, 11223, output every translation of the number.

Répondre

## Réponses aux questions d'entretien

13 réponse(s)

9

Well I think the first answer in totally wrong except the first one, Here is what I have: aabbc kvc alw kbw aavc aabw kbbc albc

chenwang le

2

In Java, a recursive solution is: public static void main(String[] args) { String s = "11223"; char[] N = s.toCharArray(); char[] S = new char[N.length]; m(0,0,N,S); } public static void m(int i, int j, char N[], char[] S){ if (i==N.length){ System.out.println(new String(S, 0, j) ); return; } S[j]=(char)('a'+Integer.parseInt(""+N[i])-1); m(i+1, j+1, N, S); if (N[i]=='1' || (N[i]=='2' && N[i+1]<'7')) { S[j]=(char)('a'+Integer.parseInt(""+N[i]+N[i+1])-1); m(i+2, j+1, N, S); } }

crisev le

1

no body use dp?

fgao le

0

c++ code: char v[100]="11223"; int n=strlen(v); void comb(int i,int j,char x[100]) { char ch; if(j==n) { cout<

Dumitru Corneliu le

0

And the output is: aabbc aabw aavc albc alw kbbc kbw kvc

crisev le

0

python code global set_str set_str = [] string = '11223' global dic dic = {} basic_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for i in range(26): dic[str(i+1)] = basic_string[i] def func(old,new): if (len(old) == 0): set_str.append(new) return if len(old) > 1: repeat_time = 2 else: repeat_time = 1 for i in range(repeat_time): key = old[:i+1] if (not key in dic): continue func(old[i+1:],new + dic[key]) func(string,'') print set_str answer:['AABBC', 'AABW', 'AAVC', 'ALBC', 'ALW', 'KBBC', 'KBW', 'KVC']

popacai le

0

Hello, here is a C++ version of crisev's working Java code :) int lengthOfCharArray(char* N){ int length=0; while(*N!='\0') { length++; N++; } return length; } void combinations(int i, int j, char* N, char* S){ if(i==lengthOfCharArray(N)){ cout<

Karim le

0

public static final char[] map = new char[] { '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; public static void translate(String N, int i, StringBuilder s) { if ( i == N.length() ) { System.out.println(s.toString()); return; } int size = 1; while ( i + size - 1 0 && n < 27 ) { s.append(map[n]); translate(N, i + size, s); s.setLength(s.length() - 1); } if (size < 2) ++size; else break; } }

Rude le

0

Haven't tested yet but here is my implementation in PHP. Feedbacks are welcomed. function myChr(\$num){ return chr(\$num + 97); } function printChars(\$string){ if( strlen(\$string) === 0){ return; } echo myChr((int)\$string[0]) . printChars(substr(\$string, 1)); echo myChr((int)substr(\$string, 0, 2)) . printChars(\$string, 2); }

Duy Nguyen le

0

besides chenwang, none of the above comment is correct

Utilisateur anonyme le

0

Here is the revised version: function myChr(\$num){ return chr(\$num + 97); } function printChars(\$string){ if( strlen(\$string) === 0){ return; } echo myChr((int)\$string[0]) . printChars(substr(\$string, 1)); echo myChr((int)substr(\$string, 0, 2)) . printChars(substr(\$string, 2)); }

Duy Nguyen le

0

Here is the correct class in C# created by me. and it gives all the translations in lexicographic order. public class StringTranslation { public static void Translate(int number) { string str = number.ToString(); int n = str.Length/2; for (int i = 1; i 26) break; else { char ch = (char)((byte)num + 64); finalstr = finalstr + ch; j++; } } else { int num = int.Parse(str[j].ToString()); char ch = (char)((byte)num + 64); finalstr = finalstr + ch; } } if (j >= str.Length) Console.WriteLine(finalstr); comb = StringTranslation.NextCombination(comb, str.Length-1); } } } public static int[] FirstCombination(int t) { int[] comb = new int[t]; for (int i = 0; i 2) break; } if (comb[i] < n-1) comb[i]++; else return null; for (int j = 0; j < i; j++) comb[j] = j * 2; return comb; } }

VarunRao le

1

aabbc aabcb aacbb aacbc aabcb acbba abcba abbca caabb bcaab bbcaa abbca

deepak le

## Ajouter des réponses ou des commentaires

Pour commenter ceci, connectez-vous ou inscrivez-vous.