English | Magyar
JS ki | CSS ki | Ékezetek ki | HiContrast
Lapozó:  (0 - 1424) 
<== | ==>
Ugrás a végére | Összes megjelenítése | Utolsó oldal
OpenOpera patches | Opera-SSL patches | Opera 12.15 source (Git repository) | Opera 12.15 source (Torrent) | Opera internal pages | Otter Browser Linux x64 - Qt5.15.2/QtWebKit5.602.1 (2024.04.27. 20:05)
OS for MC680x0 | OS for PPC | OS for Sparc64 | besztofbégéaefcé | CSÉNDZSLOG | WebToolz | DDG Shit Filter | Google Shit Filter | Progz | Fast CSS Box | Browser | OS | Agent | Statisztika | BBCode
Monospace font-family: Courier New | Browser default monospace
Email értesítő / Email notification ===> 
Keresés
Σ: 1 post

TCH  (statz) Főfasz
#1, Főfasz (10443)
4926 | #257f | ^ | Idézet | Wed, 08 May 2013 05:52:41 +02
78.92.*.* Linux x86 Opera Classic Hungary *.catv.pool.telekom.hu
@saxus:
Kevered a GNUizmust és a Linuxizmust az UNIX-al :)
Nem, azt nagy általánosságban mondtam.
De az XML-nek a gyökereit még mindig a mikrofosos világrészen kell keresni. :P
#include <stdio.h>
#include <termios.h>

unsigned short int read_num()
{
	char tmp[4];
	unsigned short int res = 0;
	int i = 0;
	int j;
	char c = 0;
	while (c != 10)
	{
		c = getchar();
		if (c != 10)
		{
			if (((c == 8) || (c == 127)) && (i > 0))
			{
				--i;
				printf("\b");
				printf(" ");
				printf("\b");
			}
			else
			{
				if ((c > 0x2f) && (c < 0x3a) && (i < 4))
				{
					tmp[i++] = c - 0x30;
					printf("%c", c);
				}
			}
		}
	}
	c = 0;
	printf("\n");
	for (j = 0; j < i; ++j)
	{
		res = (res * 10) + tmp[j];
	}
	return res;
}


int copy_even(unsigned short int val, int pos, char *tt)
{
	unsigned short int tmp, div;
	int i;
	div = 1000;
	for (i = 0; i < 3; ++i)
	{
		if (val >= div)
		{
			tmp = val / div;
			if ((tmp % 2) == 0)
			{
				tt[pos] = tmp + 0x30;
				pos++;
			}
			val -= tmp * div;
		}
		div /= 10;
	}
	if ((val % 2) == 0)
	{
		tt[pos++] = val + 0x30;
	}
	return pos;
}

int copy_odd(unsigned short int val, int pos, char *tt)
{
	unsigned short int tmp, div;
	int i;
	div = 1000;
	for (i = 0; i < 3; ++i)
	{
		if (val >= div)
		{
			tmp = val / div;
			if ((tmp % 2) != 0)
			{
				tt[pos++] = tmp + 0x30;
			}
			val -= tmp * div;
		}
		div /= 10;
	}
	if ((val % 2) != 0)
	{
		tt[pos++] = val + 0x30;
	}
	return pos;
}


int merge(char *i0, char *i1, char *o)
{
	int i = 0;
	int j = 0;
	while (i0[i] != 0)
	{
		o[j++] = i0[i++];
	}
	i = 0;
	while (i1[i] != 0)
	{
		o[j++] = i1[i++];
	}
	return j - 1;
}


void quicksort( char a[], int l, int r)
{
	int j;
	if(l < r) 
	{
		j = partition(a, l, r);
		quicksort(a, l, j - 1);
		quicksort(a, j + 1, r);
	}
}


int partition( char a[], int l, int r)
{
	int pivot, i, j, t;
	pivot = a[l];
	i = l;
	j = r + 1;

	while(1)
	{
		do ++i; while(a[i] <= pivot && i <= r);
		do --j; while(a[j] > pivot);
		if(i >= j) break;
		t = a[i];
		a[i] = a[j];
		a[j] = t;
	}
	t = a[l];
	a[l] = a[j];
	a[j] = t;
	return j;
}


void count_lower8(unsigned short int *x, int *y)
{
	int i;
	for (i = 0; i < 8; ++i)
	{
		y[i] = 0;
	}
	for (i = 0; i < 10; ++i)
	{
		++y[x[i] & 7];
	}
}

void print_lower8(int *y)
{
	int i;
	for (i = 0; i < 8; ++i)
	{
		printf("%d\n", y[i]);
	}
}


int x2 = 0, x3 = 0;

void menu2()
{
	x2 = 1;
}

void menu3()
{
	if (x2 == 0)
	{
		printf("Hiba!\n");
	}
	else
	{
		x3 = 1;
	}
}

void menu4()
{
	if ((x2 == 0) || (x3 == 0))
	{
		printf("Hiba!\n");
	}
}

int main()
{
	static struct termios old, new;
	unsigned short int t1[10];
	char t2[41];
	char t3[41];
	char t4[81];
	int t5[8];
	int i, t2p = 0, t3p = 0;
	char c = 0;
	int l = 0;

	tcgetattr(0, &old);
	new = old;
	new.c_lflag &= ~ICANON;
	new.c_lflag &= ~ECHO;
	tcsetattr(0, TCSANOW, &new);

	for (i = 0; i < 42; ++i)
	{
		t2[i] = 0;
		t3[i] = 0;
		t4[i] = 0;
		t4[i + 40] = 0;
	}

	for (i = 0; i < 10; ++i)
	{
		t1[i] = read_num();
		t2p = copy_even(t1[i], t2p, &t2);
		t3p = copy_odd(t1[i], t3p, &t3);
	}

	l = merge(&t2, &t3, &t4);
	quicksort(t4, 0, l);
	puts(t4);

	count_lower8(&t1, &t5);

	print_lower8(&t5);

	c = 0;
	while (c != 0x35)
	{
		c = getchar();
		if (c == 0x32)
		{
			menu2();
		}
		if (c == 0x33)
		{
			menu3();
		}
		if (c == 0x34)
		{
			menu4();
		}
	}

	tcsetattr(0, TCSANOW, &old);
}
Dugig van ostobaságokkal, de így kérte. Pl. a menühöz feleslegesek a plusz függvények, meg azonfelül a 4-esnél felesleges vizsgálni a kettesre is, hiszen a hármas csak akkor futhat le, ha a kettes már lefutott, vagyis ha a hármasra vizsgálunk, akkor a kettest is lefedjük vele... Vagy a dupla konverzió az elején. Azt is ő kérte. A párosvizsgálatot, szorzásokat, osztásokat direkt nem optimalizáltam ki bitforgatásra, meg bool műveletekre, ne legyen feltűnő. A páros és páratlan másolása is lazán belefért volna egyetlen függvénybe, hiszen a különbség függvényenként két karakter...mindegy. Amit kért ez a buzeráns, tanarak szégyene, azt megkapta, működik, leteszteltem, de ha az lesz a kifogás, hogy nem így gondolta azzal nem tudok mit kezdeni. Akasszátok fel.
A warningokkal, notekkal nem kell törődni, müxik.
Apropó, Linuxon is van getch(), a getchar()-t kell átkapcsolni így:
static struct termios old, new;
tcgetattr(0, &old);
new = old;
new.c_lflag &= ~ICANON;
new.c_lflag &= ~ECHO;
tcsetattr(0, TCSANOW, &new);
Eztán a getchar() getch()-ként viselkedik. Visszakapcsolása így történik:
tcsetattr(0, TCSANOW, &old);
Ja, kell hozzá még egy #include <termios.h> is, oszt csá.

Ha meg azt akarod, hogy getche() legyen, akkor a fent beírt kódban az ~ECHO elől a ~ eltűnik és ennyi.


English | Magyar
JS ki | CSS ki | Ékezetek ki | HiContrast
Lapozó:  (0 - 1424) 
<== | ==>
Ugrás a végére | Összes megjelenítése | Utolsó oldal
OpenOpera patches | Opera-SSL patches | Opera 12.15 source (Git repository) | Opera 12.15 source (Torrent) | Opera internal pages | Otter Browser Linux x64 - Qt5.15.2/QtWebKit5.602.1 (2024.04.27. 20:05)
OS for MC680x0 | OS for PPC | OS for Sparc64 | besztofbégéaefcé | CSÉNDZSLOG | WebToolz | DDG Shit Filter | Google Shit Filter | Progz | Fast CSS Box | Browser | OS | Agent | Statisztika | BBCode
Monospace font-family: Courier New | Browser default monospace
Email értesítő / Email notification ===> 
Keresés

Név: (max 255 byte)

Email: (max 255 byte) Nem kötelező!

Üzenet: (max 65536 kar.) 65536-0=65536




crap_vkn v4.34.0 by TCH
Thx to saxus for the escaped string decoder function (PHP), the realIP function (PHP) & the SQL handle layer (PHP), to thookerov for the int_divide function (PHP), to Jeff Anderson for the getSelText function (JS), to Alex King for the insertAtCursor function (JS), Flood3r for the new CSS styles, Pety for the spamprotection idea and some design and comfort ideas, MaxMind for the IP2Country database, famfamfam for the flags of countries and an unknown PHP programmer for the removeAccents function.



Kecskebaszók ide!