Menu
CoddyTech

프로젝트: 명령 처리기

Coddy의 PHP 개발자를 위한 C++ 코스 레슨. 48개 중 46번째.

challenge icon

챌린지

쉬움

프로젝트 단계 4: 이전 단계를 모두 유지하세요. process를 구현하세요. 새 Catalog를 만들고, 명령은 add title copies, borrow title, return title 형식입니다. 형식이 잘못된 명령, 추가 필드, 중복 항목, 누락된 제목 및 불가능한 대여는 거부하세요. 거부된 각 행마다 횟수를 1씩 늘리세요. 양쪽에 공백을 둔 | rejected:COUNT를 보고서 뒤에 반환하세요. 입력은 단계 4 다음에 명령이 옵니다. 빈 명령 묶음은 empty | rejected:0을 반환합니다.

편집 가능한 모듈: Book.cpp, Book.hpp, LoanPolicy.cpp, LoanPolicy.hpp, Catalog.cpp, Catalog.hpp, processor.cpp, processor.hpp. 각 필수 타입에는 이름이 지정된 헤더와 구현 파일이 있습니다. 모든 공개 시그니처를 그대로 유지하세요. 잠긴 main.cpp는 표준 입력을 읽고 API를 직접 호출합니다. 또한 명시된 곳에서는 공개 API의 동작을 독립적으로 검사합니다. API 내부에서 출력하지 말고 값을 반환하세요. 정수 입력과 결과는 부호 있는 int 범위에 들어갑니다. 별도 언급이 없으면 텍스트는 ASCII입니다.

직접 해보기

#include "processor.hpp"
#include <iostream>
int main(){

std::vector<std::string> rows; std::string line; while(std::getline(std::cin,line)) rows.push_back(line);
int stage=std::stoi(rows.at(0));
if(stage>=1){Book b("probe",1);if(b.title()!="probe"||b.available()!=1||!b.borrow()||b.borrow())return 31;b.give_back();if(b.available()!=1)return 32;}
if(stage>=2){LoanPolicy p(7,3);if(p.fee(5)!=0||p.fee(7)!=0||p.fee(9)!=6)return 33;}
if(stage>=3){Catalog c;if(!c.add("a",1)||c.add("a",3)||c.add("b",-1)||!c.borrow("a")||c.borrow("a")||c.borrow("missing")||c.available("missing")!=-1||!c.give_back("a")||c.report()!="a:1")return 34;}
if(stage==1){std::istringstream in(rows.at(1));std::string t;int n,k;in>>t>>n>>k;Book b(t,n);int success=0;for(int i=0;i<k;++i)if(b.borrow())++success;std::cout<<b.title()<<" "<<success<<" "<<b.available()<<"\n";}
else if(stage==2){std::istringstream in(rows.at(1));int d,f,e;in>>d>>f>>e;LoanPolicy p(d,f);std::cout<<p.fee(e)<<"\n";}
else if(stage==3){Catalog c;for(size_t i=1;i<rows.size();++i){std::istringstream in(rows[i]);std::string t;int n;in>>t>>n;c.add(t,n);}std::cout<<c.report()<<"\n";}
else if(stage==4){std::cout<<process(std::vector<std::string>(rows.begin()+1,rows.end()))<<"\n";}

}

PHP 개발자를 위한 C++의 모든 레슨

직접 연습해 보세요: 온라인 C++ 컴파일러