#include #define VELKOST 10 #define MAX 10000 struct ucet { int c; long peniaze; } ucty[MAX]; int pocet; long sucet; char castka[ 1024 ]; int najdiucet( int c ) { int i; for ( i = 0; i < pocet; i++ ) if ( c == ucty[ i ].c ) return i; return -1; } void zaloz( void ) { int c; scanf( "%d\n", &c ); if ( najdiucet( c ) != -1 ) { printf( "Ucet %010d uz existuje.\n\n", c ); return; } ucty[ pocet ].peniaze = 0; ucty[ pocet ].c = c; pocet++; printf( "Ucet %010d vytvoren.\n\n", c ); } void uloz( void ) { int i; int c; long a, b; long spolu; scanf( "%d %s", &c, castka ); sscanf( castka, "%ld.%ld", &a, &b ); i = najdiucet( c ); if ( i == -1 ) { printf( "Ucet %010d neexistuje.\n\n", c ); } else { printf( "Ulozeno %s na ucet %010d.\n\n", castka, c ); spolu = a * 100 + b; ucty[ i ].peniaze += spolu; sucet += spolu; } } void vyber( void ) { int i; int c; long a, b, spolu; scanf( "%d %s", &c, castka ); sscanf( castka, "%ld.%ld", &a, &b ); spolu = 100 * a + b; i = najdiucet( c ); if ( i == -1 ) { printf( "Ucet %010d neexistuje.\n\n", c ); } else if ( ucty[ i ].peniaze < spolu ) { printf( "Nedostatek penez.\n\n" ); } else { printf( "Vybrano %s z uctu %010d.\n\n", castka, c ); ucty[ i ].peniaze -= spolu; sucet -= spolu; } } void preved( void ) { int i, j; int c, c2; long a, b, spolu; scanf( "%d %d %s", &c, &c2, castka ); sscanf( castka, "%ld.%ld", &a, &b ); spolu = a * 100 + b; i = najdiucet( c ); j = najdiucet( c2 ); if ( i == -1 ) { printf( "Ucet %010d neexistuje.\n", c ); } else if ( ucty[ i ].peniaze < spolu ) { printf( "Nedostatek penez.\n" ); } else if ( j != -1 ) { printf( "Prevedeno %s z uctu %010d na ucet %010d.\n", castka, c, c2 ); ucty[ i ].peniaze -= spolu; ucty[ j ].peniaze += spolu; } if ( j == -1 ) { printf( "Ucet %010d neexistuje.\n", c2 ); } printf( "\n" ); } void reset( void ) { pocet = 0; sucet = 0; } void list( int bList ) { int i; printf( "Pocet uctu : %d\n", pocet ); if ( bList ) { for ( i = 0; i < pocet; i++ ) { printf( "%010d%7ld.%02ld\n", ucty[ i ].c, ucty[ i ].peniaze / 100, ucty[ i ].peniaze % 100 ); } } printf( "Celkem %7ld.%02ld\n\n", sucet / 100, sucet % 100 ); } int main( void ) { char command[ 30 ]; reset(); while (!feof( stdin) ){ if ( scanf( "%s", command ) == 1 ) { if ( !strcmp( command, "ZALOZ" ) ) zaloz(); else if ( !strcmp( command, "ULOZ" ) ) uloz(); else if ( !strcmp( command, "VYBER" ) ) vyber(); else if ( !strcmp( command, "PREVED" ) ) preved(); else if ( !strcmp( command, "STATISTIKA" ) ) list( 0 ); else if ( !strcmp( command, "LIST" ) ) list( 1 ); else if ( !strcmp( command, "RESET" ) ) { reset(); printf( "Reset systemu.\n\n" ); } else { printf( "Konec.\n" ); return 0; } } } printf( "Konec.\n" ); return 0; }