A - The First Day at School
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87157#problem/A

Description

Vasya is a young and very promising android. Today is his first day at University. Vasya has very carefully studied the list of all courses on the wall near the Dean’s office and has chosen the ones to attend. Now he wants to write down his own week timetable. Help him do this.
 

Input

The first line contains an integer n that is the number of courses Vasya is going to attend (1 ≤ n ≤ 12). After that the courses are listed, each is described in two lines.
The first line of a course description contains its name. The name of the course may consist of up to five words, which are divided by exactly one space (there are no spaces before the first word and after the last one). The words consist of capital and lowercase Latin letters. The length of every word is within the range from 1 to 10.
The second line of a course description contains the day of week and the number of a lesson, when it takes place. The day of week may take one of the three values: “Tuesday”, “Thursday” и “Saturday”. The number of a lesson is an integer from 1 to 4. There are no two courses, Vasya has chosen, taking place at the same time.

Output

Output the timetable as a table of the size 4×3. The columns of the table should correspond to the three academic days: the first column — to Tuesday, the second — to Thursday, the third — to Saturday. The rows should correspond to the four classes. The width of each column should be equal to 10 characters. The height of the row of the table equals to the height of the highest of its cells. If all the cells in the row are empty then the height of the row should be equal 1 character. If some word doesn’t find room in the current line, it should be placed in the next line. The text in the cell should be aligned to top and left borders. Make the table itself using characters “-” (ASCII 45), “+” (ASCII 43) and “|” (ASCII 124).

Sample Input

9
Physics
Thursday 3
Maths
Tuesday 1
Chemistry
Thursday 1
Physical education
Saturday 2
Astronomy
Saturday 4
Urban geography
Tuesday 4
History
Saturday 1
Modeling
Thursday 2
Biology
Thursday 4

Sample Output

+----------+----------+----------+
|Maths |Chemistry |History |
+----------+----------+----------+
| |Modeling |Physical |
| | |education |
+----------+----------+----------+
| |Physics | |
+----------+----------+----------+
|Urban |Biology |Astronomy |
|geography | | |
+----------+----------+----------+

HINT

题意

模拟题,画课表

题解

注意,如果这行塞满了,就换行就好了

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
string s1 = "Tuesday";
string s2 = "Thursday";
string s3 = "Saturday";
string str;
vector<string>name;
int flag[]; vector<string>vi[][]; void CHANGE()
{
int pre = ;
for(int i = ; i < str.size() ; ++ i)
{
if (str[i] == ' ' || i == str.size() - )
{
string t1;
t1.clear();
if (i == str.size() - ) i ++;
for(int k = pre ; k < i ; ++ k)
{
t1.pb(str[k]);
}
name.pb(t1);
pre = i + ;
}
}
} int main(int argc,char *argv[])
{
int n;
memset(flag,,sizeof(flag));
cin >> n ;getchar();
for(int i = ; i < n ; ++ i)
{
str.clear();
getline(cin,str);
name.clear();
CHANGE();
string day;
int r;
int c;
cin >> day >> r; getchar();
if (day == s1) c = ;
else if(day == s2) c = ;
else c = ;
int flag = ;
string tt1;
for(int j = ; j < name.size() ; ++ j)
{
if (tt1.size() + name[j].size() + flag > )
{
vi[r][c].pb(tt1);
tt1.clear();
tt1 = name[j];
flag = ;
}
else
{
if (flag == ) flag = ;
else tt1 += ' ';
tt1 += name[j];
}
}
if (tt1.size() >= ) vi[r][c].pb(tt1);
}
for(int i = ; i <= ; ++ i)flag[i] = ;
for(int i = ; i <= ; ++ i)
{
for(int j = ; j <= ; ++ j)
flag[i] = max(flag[i],(int)vi[i][j].size());
}
cout <<"+----------+----------+----------+" <<endl;
for(int i = ; i <= ; ++ i)
{
for(int t = ; t <= flag[i] ; ++ t)
{
cout << "|";
for(int j = ; j <= ; ++ j)
{
int bg = ;
if (vi[i][j].size() >= t)
{
cout << vi[i][j][t-];
bg = vi[i][j][t-].size();
}
for(int r = bg + ; r <= ; ++ r) cout << " ";
cout << "|";
}
cout << endl;
}
cout <<"+----------+----------+----------+" <<endl;
}
return ;
}

最新文章

  1. 前端精选文摘:BFC 神奇背后的原理
  2. 使用MapReduce实现一些经典的案例
  3. python访问数据库一
  4. plsql无法连接64位oracle数据库的解决方法(图文解说)
  5. Winform开发的界面处理优化
  6. JQ限制输入字数,并提示剩余字数
  7. C#相关时间DateTime格式化
  8. C# 枚举运用&quot;位&quot;操作和&quot;或&quot;操作
  9. 製程能力介紹(SPC introduction) ─ 製程能力改善及評估
  10. 从Android源码修改cpu信息
  11. 升级Jenkins版本
  12. 『MySQL』时间戳转换
  13. MySQL------报错Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:NO)解决方法
  14. 面经:Bloomberg Internship第一轮
  15. BinarySearch
  16. 如何使用 Visual C# 2005 或 Visual C# .NET 向 Excel 工作簿传输数据
  17. IE盒模型与W3C盒模型区别
  18. div + css 样式连接
  19. mongoexport
  20. Git使用教程(转载)

热门文章

  1. mysql SQL_MODE设置
  2. 滑屏 H5 开发实践九问
  3. Spring 事务管理原理探究
  4. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(4)
  5. Most Powerful(ZOJ 3471状压dp)
  6. javascript 继承、命名空间实现分享
  7. openfl关于windows平台编译报错解决办法
  8. LeetCode题解——Roman to Integer
  9. JQuery插件之图片轮播插件–slideBox
  10. Codeforces Round #363 (Div. 1) C. LRU