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

From AdonaiMedrado.Pro.Br
Revision as of 12:42, 29 April 2009 by 200.17.147.2 (Talk) (New page: <code lang="c"> #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] = "ABCDEFGHIJKLMN...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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;
 
}