/*
基本情報技術者試験 平成9年度・秋期・午後 問11
BohYoh Shibata PREPARATION
*/
#include <stdio.h>
#include <stdlib.h>
#define KEEPTEMP 95.0
#define FUTTEN 100.0
#define CAPACITY 2000
#define errexit(p1) \
{printf("指示誤りのため処理を中止します。\n"); \
exit(p1); }
double temp_up( int, double );
double temp_down( int, double );
main()
{
int dest, opecd, status = 0;
double wtrtemp;
long evtime = 0; /* 操作指示を実行する時刻 */
long curtime = 0; /* 現在の時刻 */
double curtemp = 90.0; /* 現在の湯温 */
int vol = 2000; /* 現在の湯量 */
FILE *fp;
printf( "\n 温度変化状況\n\n 経過時間 湯量 温度\n" );
fp = fopen( "input.dat", "r" );
fscanf( fp, "%d %ld", &opecd, &evtime );
if( evtime < curtime ) errexit(1);
while( 1 ) {
if( evtime == curtime ) {
switch( opecd ){
case 1:
fscanf( fp, "%d", &dest );
vol -= dest;
if ( vol < 0 ) vol = 0;
break;
case 2:
status = 1;
break;
case 3:
fscanf( fp, "%lf", &wtrtemp );
curtemp = ( curtemp * (double)vol
+ wtrtemp * (double)(CAPACITY - vol))
/ (double)CAPACITY;
vol = CAPACITY;
break;
case 4:
fclose(fp);
printf( "%5ld %4d %6.2f\n", curtime, vol, curtemp );
exit(0);
default:
errexit(1);
}
printf( "%5ld %4d %6.2f\n", curtime, vol, curtemp );
fscanf( fp, "%d %ld", &opecd, &evtime );
if( evtime <= curtime ) errexit(1);
}
else
printf( "%5ld %4d %6.2f\n", curtime, vol, curtemp );
if( curtemp < KEEPTEMP ) status = 1;
else if( curtemp == FUTTEN ) status = 0;
if( status == 1 ) curtemp = temp_up( vol, curtemp );
else curtemp = temp_down( vol, curtemp );
curtime++;
}
}