Új hozzászólás Aktív témák
-
dany27
őstag
válasz
Jester01
#2982
üzenetére
Íme:
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#include<string.h>
#define ESC 27
#define ENTER 13
#define BS 8
typedef struct ag{
char betu;
struct ag *jobb,*bal;
} Fa;
Fa* uj()
{
Fa* elem=(Fa*)malloc(sizeof(Fa));
elem->bal=NULL;
elem->jobb=NULL;
return elem;
}
void insert(Fa* root, char betu, char *kod)
{
Fa *hely, *elozo;
int i=0;
hely=root;
while (kod[i]!='\0')
{
elozo=hely;
if (kod[i]=='.')
hely=hely->jobb;
else
hely=hely->bal;
if (hely==NULL)
{
hely=uj();
if (kod[i]=='.')
elozo->jobb=hely;
else
elozo->bal=hely;
}
i++;
}
hely->betu=betu;
}
void check(Fa *root,char kod[7])
{
Fa *hely;
int i=0;
hely=root;
while(kod[i]!='\0' && hely!=NULL)
{
if(kod[i]=='.')
hely=hely->jobb;
else
hely=hely->bal;
i++;
}
if(hely!=NULL)
printf("\n%c",hely->betu);
else
printf("\nA megadott morse kod helytelen!");
}
void fill(Fa* root)
{
insert(root, 'A', ".-");
insert(root, 'B', "-...");
insert(root, 'C', "-.-.");
insert(root, 'D', "-..");
insert(root, 'E', ".");
insert(root, 'F', "..-.");
insert(root, 'G', "--.");
insert(root, 'H', "....");
insert(root, 'I', "..");
insert(root, 'J', ".---");
insert(root, 'K', "-.-");
insert(root, 'L', ".-..");
insert(root, 'M', "--");
insert(root, 'N', "-.");
insert(root, 'O', "---");
insert(root, 'P', ".--.");
insert(root, 'Q', "--.-");
insert(root, 'R', ".-.");
insert(root, 'S', "...");
insert(root, 'T', "-");
insert(root, 'U', "..-");
insert(root, 'V', "...-");
insert(root, 'W', ".--");
insert(root, 'X', "-..-");
insert(root, 'Y', "-.--");
insert(root, 'Z', "--..");
insert(root, '0', "-----");
insert(root, '1', ".----");
insert(root, '2', "..---");
insert(root, '3', "...--");
insert(root, '4', "....-");
insert(root, '5', ".....");
insert(root, '6', "-....");
insert(root, '7', "--...");
insert(root, '8', "---..");
insert(root, '9', "----.");
insert(root, '.', ".-.-.-");
insert(root, ',', "--..--");
insert(root, ':', "---...");
insert(root, '?', "..--..");
insert(root, '-', "-....-");
insert(root, '/', "-..-.");
insert(root, '(', "-.--.-");
insert(root, '@', ".--.-.");
insert(root, '=', "-...-");
}
void clreol()
{
int i;
printf("\r");
for(i=1;i<80;i++)
{
printf(" ");
}
printf("\r");
}
void felszabadit(Fa *root)
{
if (root==NULL)
return;
felszabadit(root->jobb);
felszabadit(root->bal);
free(root);
}
int main()
{
Fa* root=uj();
char beolv[7];
int index=0;
int key=0;
fill(root);
printf("Morse kod ellenorzo! Adatbevitel megszakitalsa az ESC lenyomasaval!\n");
printf("Morse kod: ");
do
{
key=getch();
if(((key>=45) && (key<=46)) && (index<6))
{
beolv[index]=(char)key;
index++;
printf("%c",(char)key);
}
else if(key==BS && strlen(beolv)>0)
{
beolv[index-1]=(char)0;
index--;
clreol();
printf("Morse kod: %s",beolv);
}
}while((key!=ESC) && (key!=ENTER || index==0));
beolv[index]='\0';
if(key==ENTER)
check(root,beolv);
else
printf("Adatbevitel megszakitva");
felszabadit(root);
return 0;
}Ezzel próbáljátok ki:
.-. Ez elvileg R betűt ad ami helyes.
.-.- Ez G-t ad ami nem helyes mivel a G morse kódja --. és ha ezt beírom erre is G-t ad![ Módosította: #65675776 ]
Új hozzászólás Aktív témák
● olvasd el a téma összefoglalót!
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- AKCIÓ 03.30-ig!!! Intel Core ULTRA 9 285K +2x16GB 7600MHz Patriot Viper XTREME 5! (Bolti ár: 600e!)
- AKCIÓ 03.30-ig!!! Intel Core ULTRA 9 285K +2x16GB 7600MHz Patriot Viper XTREME 5! (Bolti ár: 600e!)
- 0 perces COOLER MASTER 650W MWE V2 minőségi tápegység! GAR/SZÁMLA (Te nevedre)! 12V: 54A!
- AKCIÓ 03.30-ig!!! Intel Core ULTRA 5 225F +32GB DDR5 kit +hűtött VRM-es alaplap! GAR/SZÁMLA!
- AKCIÓ 03.30-ig!!! Intel Core ULTRA 5 225F +32GB DDR5 kit +hűtött VRM-es B860 lap! GAR/SZÁMLA!
- 3év! AKCIÓ! ÚJ ASUS TUF GAMING Geforce RTX 5080 OC Edition 16GB VRAM Ray Tracing DLSS4
- ÁRGARANCIA!Épített KomPhone i5 14400F 32/64GB RAM RX 9060 XT 8GB GAMER PC termékbeszámítással
- 27% - ÚJ ASUS ROG Strix 27" XG27AQDNG OLED Monitor! 2560x1440 / 360Hz / 0.03ms / G-Sync / FreeSync
- Xiaomi 14T Pro 512GB,Újszerű,Dobozaval,12 hónap garanciával
- HIBÁTLAN iPhone 12 256GB Blue-1 ÉV GARANCIA - Kártyafüggetlen, MS4462
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
