Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HTML Timetable generator.cpp
#include <cstdlib> #include <iostream> #include <vector> #include <utility> #include <limits> #include <stdexcept> #include <string> using std::cout; using std::vector; using std::cin; using std::clog; using std::string; unsigned day, finish, table_bgn=0xFFFFFFFF, table_end=0; vector<vector<std::pair<string, string> > > out(7); vector<string> hrs; class bistring; string& _in(bistring&); class bistring{ protected: string prev; string& move(const string& v){prev=std::move(actual); return actual=v;} friend string& _in(bistring&); public: string actual; operator string&(){return actual;} }; #define VAL(what) //clog<<#what<<'='<<what<<'\n' void print_results(){ cout<<"<table border=3>"; VAL(table_bgn); VAL(table_end); VAL(day); for(unsigned i=table_bgn; i<table_end; ++i){ VAL(i); cout<<"<tr><td><p style=\"text-align: center\">"<<hrs[i]<<"</p></td>\n"; for(unsigned j=0; j<=day; ++j){ VAL(j); cout<<"\t<td>"; try{ auto temp=out[j].at(i); if(temp.first=="") throw std::out_of_range(""); /*cout<<"<table><tr>" "<td><p style=\"text-align: right\">";*/ cout<<temp.first<<' ' /* <<"</p></td>" "<td><p style=\"text-align: left\">"*/ <<temp.second; /*cout<<"</p></td>" "</tr></table>";*/ } catch(std::out_of_range&){} cout<<"</td>\n"; } cout<<"</tr>"; } cout<<"</table>\n"; } struct next_day{ next_day()=default; next_day(unsigned _v){finish=_v-1;} }; struct done:next_day{ ~done(){ print_results(); exit(0); } }; string& _in(bistring &in){ string temp; for(;;){ cin>>temp; if(temp[0]=='#'){ if(temp.size()>=2){ if(temp[1]=='#') throw done(); if(temp[1]=='-') return in.move(""); if(temp[1]=='_') return in.prev; if(temp[1]>='0' && temp[1]<='9') throw next_day(std::stoul(temp.substr(1))); } cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } else return in.move(temp); } } #define IN(arg) _in(arg) bistring _in2(bool(*func)(const string&), string CONDITION){ for(;;){ bistring temp; IN(temp); if(!func(temp.actual)) cout<<"Odrzucono token \""<<temp.actual<<"\", ponieważ nie spełnia warunku "<<CONDITION<<'\n'; else return temp; } } #define IN2(CONDITION) in=_in2([](const string& temp){return temp CONDITION;}, #CONDITION) int main(){ bistring in, in2; try { for(;;){ in=IN2(.size()==8); string result(1, in.actual[0]); result+=in.actual[1]; result+=':'; result+=in.actual[2]; result+=in.actual[3]; result+=" - "; result+=in.actual[4]; result+=in.actual[5]; result+=':'; result+=in.actual[6]; result+=in.actual[7]; hrs.push_back(result); } } catch (next_day&) {} for(day=0;; ++day){ for(unsigned j=1; j<=finish; ++j) out[day].emplace_back(); if(finish<table_bgn) table_bgn=finish; try { for(;;){ IN(in); IN(in2); out[day].emplace_back(in.actual, in2.actual); } } catch (next_day&) { if(out[day].size()>table_end) table_end=out[day].size(); } } }
run
|
edit
|
history
|
help
0
Compute Power Manually
lref assignment
even number
Program to Time Difference
std::99 bottles of beer!
Simple Generic Data Type Example
vector flavors....
insertion sort
numeric_limits
Crow unordered_map Quiz