#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int atalakitasEsEllenorzes(char *t1,int szamrendszer){
char t2[160];
int i,j;
for(i = 0, j = 0; t1[i] != '\0'; i++, j++){
if(t1[i] >= '0' && t1[i] <= '9'){
t2[j] = t1[i];
continue;
}
int a = t1[i] - 55;
t2[j] = (a / 10) + '0';
j++;
t2[j] = (a % 10) + '0';
}
for(i = 0; t2[i] != '\0'; i++){
if(!((t2[i] - '0') < szamrendszer))
return -1;
}
}
bool beolvasasEsHibakereses(int *mibol, int *mibe, char *tomb){
FILE *f;
if(f == NULL)
return false;
if(fscanf(f
,"%d %d %s\n",mibol
,mibe
,tomb
)){
int i;
if(!(2 <= *mibol && *mibol <= 36 && 2 <= *mibe && *mibe <= 36)){
return false;
}
for(i = 0; tomb[i] != '\0'; i++){
if(('0' <= tomb[i] && tomb[i] <= '9') || ('A' <= tomb[i] && tomb[i] <= 'Z'))
continue;
return false;
}
}
if(atalakitasEsEllenorzes(tomb,*mibol) == -1){
return false;
}
return true;
}
char dec_to_hex_kiir(int _dec){
char c;
if(_dec < 10)
c = _dec + '0';
else
c = (55 + _dec);
return c;
}
void eredmenyToFile(char *_eredmeny){
FILE *wr;
wr
= fopen("ki.txt","w");
if(wr != NULL){
}
}
void atvaltas(int _mibol, int _mibe, unsigned int _szam, char *eredmeny){
unsigned long long int temp = _szam;
unsigned long long int digits[16], tizes_szamrendszer = 0;
int j, i = -1;
while(temp){
digits[++i] = temp % 10;
temp /= 10;
}
if(_mibol != 10){
for(j = 0; j <= i; j++){
int szorzas = 1,k;
for(k = 1; k <= j; k++){
szorzas *= _mibol;
}
tizes_szamrendszer += digits[j] * (szorzas);
}
}
else{
tizes_szamrendszer = _szam;
}
for(j = 0, i = 0; j != 1; i++){
eredmeny[i] = dec_to_hex_kiir(tizes_szamrendszer % _mibe);
tizes_szamrendszer /= _mibe;
if(tizes_szamrendszer == 0){
j++;
}
}
i = 0;
char temp2;
while (i < j) {
temp2 = eredmeny[i];
eredmeny[i] = eredmeny[j];
eredmeny[j] = temp2;
i++;
j--;
}
}
int main()
{
char tomb[160];
int mibol, mibe;
unsigned long long int szam;
char eredmeny[16] = "";
if(!beolvasasEsHibakereses(&mibol,&mibe,tomb)){
}
else{
szam = atalakitasEsEllenorzes(tomb,mibol);
atvaltas(mibol,mibe,szam,eredmeny);
}
eredmenyToFile(eredmeny);
return 0;
}
{"text":"text","html5":"html","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"lua","bash":"sh","erlang":"erlang","go":"golang","c":"c_cpp","cpp":"c_cpp","diff":"diff","latex":"latex","sql":"sql","xml":"xml","0":"text","abap":"abap","actionscript":"actionscript","actionscript3":"actionscript","ada":"ada","apache":"apache_conf","applescript":"applescript","asm":"assembly_x86","autohotkey":"autohotkey","closure":"closure","cobol":"cobol","coffeescript":"coffee","cpp-winapi":"c_cpp","c_loadrunner":"c_cpp","c_mac":"c_cpp","c_winapi":"c_cpp","csharp":"csharp","d":"d","dart":"dart","dot":"dot","eiffel":"eiffel","fortran":"fortran","groovy":"groovy","haskell":"haskell","haxe":"haxe","ini":"ini","io":"io","java":"java","java5":"java","make":"makefile","matlab":"matlab","mysql":"mysql","objc":"objectivec","ocaml":"ocaml","pascal":"pascal","perl":"perl","perl6":"perl","postgresql":"pgsql","powershell":"powershell","prolog":"prolog","properties":"properties","rails":"ruby","rust":"rust","scala":"scala","scheme":"scheme","smarty":"smarty","tcl":"tcl","vala":"vala","vb":"vbscript","verilog":"verilog","vhdl":"vhdl","yaml":"yaml"}