Solução: Problema do arranjo dos caracteres (Vanessa Aline)

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
#include<stdio.h>
#include<string.h>
#include<math.h>
 
int main(){
	int N, M, K;
	scanf("%d", &N);
	scanf("%d", &M);
	scanf("%d", &K);
 
	char alfabeto[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
	int i;
	char resposta[M+1];
	int aux = K-1;
	for (i=M-1; i>=0; i--){
		int j;
		for (j = N; j >= 0; j--){
			if (aux >= j*pow(N,i)){
				aux = aux - j*pow(N,i);
				resposta[M-i-1] = alfabeto[j];
				break;
			}
		}
	}
	resposta[M]='\0';
 
	printf("%s\n", resposta);
	return 0;
 
}