CAPTCHA - CAPTCHA

no tags 

in English

Implement "string captcha(int R, string P, string N)" function.

"R" is a random number of 5 digits (between 10000 and 50000 inclusive), the string "P" is "ALGORITMOS" and "N" is the user name with which you want to log in. Take the first and last character of "N", transform the numerical value of the ASCII code to which they relate and add them to "R". Sort digits of this new number in descending order, this new number will be called "A". Create a new string alternating chars of "P" with digits of "A", so that every two chars of "P" (one uppercase and other lowercase), puts a digit of "A". Then, reverse the resulting string to obtain the verification code.

Write a program that prompts a username and a random number, and then return the corresponding CAPTCHA, using the "captcha" function.

Detailed example of CAPTCHA generation:

  • R: 21300
  • P: ALGORITMOS
  • N: gomezHI83

The process of CAPTCHA generating is:

  1. First character N 'g' → ASCII (g) = 103
  2. Last character N '3' → ASCII (3) = 51
  3. Sum of the two ASCII with R: 103 + 51 + 21300 = 21454
  4. Sorting the numbers A = 54421
  5. Intermediate chain: "Al5Go4Ri4Tm2Os1"
  6. Captcha code: 1sO2mT4iR4oG5lA

Input

Username + Random number.

Output

CAPTCHA.

Example 1

Input:
gomezHI83
21300

Output:
1sO2mT4iR4oG5lA

en Español

Implementar la función "string captcha(int R, string P, string N)".

Sea R un número aleatorio de 5 cifras (comprendido entre 10000 y 50000 inclusive), P la cadena de caracteres ‘ALGORITMOS’ y N el nombre de usuario con el cual se desea iniciar sesión. Tomar el primer y último caracter de N, transformarlos al valor numérico del código ASCII al cual corresponden y sumarlos a R. Ordenar las cifras de este nuevo número de forma descendente, lo que dará lugar a un nuevo número que llamaremos A. Formar una nueva cadena que alterne los caracteres de P con las cifras de A de forma tal que cada dos caracteres de P (uno mayúscula y el siguiente minúscula) se encuentre una cifra de A. Luego, invertir la cadena resultante a fin de obtener el código de verificación.

Escribir un programa que solicite un nombre de usuario y un número aleatorio, y luego retorne el CAPTCHA correspondiente, haciendo uso de la función "captcha".

Ejemplo detallado de la generación del CAPTCHA:

Sean:

  • R: 21300
  • P: ALGORITMOS
  • N: gomezHI83

El proceso de generación de captcha es:

  1. Primer caracter de N: ‘g’ → ASCII(g) = 103
  2. Último caracter de N: ‘3’ → ASCII(3) =  51
  3. Suma de los dos ASCII con R: 103 + 51 + 21300 = 21454
  4. Ordenando las cifras A=54421
  5. Cadena intermedia: “Al5Go4Ri4Tm2Os1”
  6. Código captcha: 1sO2mT4iR4oG5lA

Entrada

Nombre de usuario + Numero aleatorio.

Salida

CAPTCHA.

Ejemplo 1

Input:
gomezHI83
21300

Output:
1sO2mT4iR4oG5lA

hide comments
Simes: 2023-04-30 22:27:31

Exactly the same as CAPTCHA2 from the same problem setter.


Added by:Coach UTN FRSF
Date:2015-08-25
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY