U E D R , A S I H C RSS

희경/엘레베이터

버젼 1
~cpp 
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	ifstream fin("input.txt");  
    int number;
	int floor;
	int people = 0;
	int in;
	int out;
	fin >> number;
	cout << number << "층짜리 건물입니다." << endl;
	while(fin >> floor >> in >>  out)
	{
        people = people + in - out;
		cout << "지금 현재 " << floor << "층에 있고" << endl
			<< in << "명이 타고 " << out << "명이 내려서" << endl
			<< people << "명 남았습니다" << endl
			<< "**************************************************" << endl;
	}
	return 0;
}


업그레이드?
~cpp 
#include<iostream> 
#include<fstream> 
using namespace std; 
int main() 
{ 
    ifstream fin("input.txt");   
    int number; 
        int floor; 
        int people = 0; 
        int in; 
        int out;
		int temp = 1;
        fin >> number; 
        cout << number << "층짜리 건물입니다." << endl; 
		while(fin >> floor >> in >>  out) 
        { 
			if(temp < floor)
			{
				while(temp+1 != floor)
				{
					temp++;
					cout << "지금 현재 " << temp << "층을 지나고 있습니다" << endl
						 << "**************************************************" << endl;  
				}
				temp++;
			}
			else if(temp > floor)
			{
				while(temp-1 != floor)
				{
					temp--;
					cout << "지금 현재 " << temp << "층을 지나고 있습니다" << endl
						<< "**************************************************" << endl;
				}
			}
			people = people + in - out; 
            cout << "지금 현재 " << floor << "층에 있고" << endl 
                  << in << "명이 타고 " << out << "명이 내려서" << endl 
                  << people << "명 남았습니다" << endl; 
            if(people > 10)
			{
				cout << "\a인원초과입니다." << endl
					 << people - 10 << "명이 내립니다." <<endl;
				people = 10;
			}
			cout << "**************************************************" << endl;
        } 
        return 0; 
} 
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:35
Processing time 0.0076 sec