gonca16 0 Posted November 17, 2020 Report Share Posted November 17, 2020 Boa tarde Estou a tentar fazer um exercicio quero criar um programa que lê-se as combinaçoes dos teclados antigos dos telemoveis por exemplo 222 2 333 33 daria "cafe" como é que posso fazer isto ? Não existe nenhuma função que agrupe os numeros num array para ficar {"222","2","333","33"}, isto facilitaria bastante o problema. Desde Ja Obrigado Link to post Share on other sites
M6 150 Posted November 17, 2020 Report Share Posted November 17, 2020 Se usares um dicionário tens o problema resolvido. Por exemplo #include <map> std::map<int, char> teclado = { { 2, 'a' }, { 222, 'c' }, { 33, 'f' } { 3, 'e' } }; 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
gonca16 0 Posted November 17, 2020 Author Report Share Posted November 17, 2020 (edited) Obrigado pela dica, obtei por fazer assim: std::map<int, string> code_map = {{ 2, "abc" },{ 3, "def" },{ 4, "ghi" }}; e dps vou la pelo tamanho da string, só mais uma coisa neste exemplo : case '2': part = code_map[2][sub_code.size()-1]; case '3': part = code_map[3][sub_code.size()-1]; a variavel "part" fica me sempre com o valor do case 3 mesmo que nem tenho nenhum 3 e nem entra ali porque razao é que fica sempre com aquele valor ? Edited November 17, 2020 by gonca16 Link to post Share on other sites
Solution M6 150 Posted November 18, 2020 Solution Report Share Posted November 18, 2020 Falta-te o break para terminares o case. 1 Report 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now