URAL 2046 A - The First Day at School 模拟题
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
Input
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 ;
}
最新文章
- 前端精选文摘:BFC 神奇背后的原理
- 使用MapReduce实现一些经典的案例
- python访问数据库一
- plsql无法连接64位oracle数据库的解决方法(图文解说)
- Winform开发的界面处理优化
- JQ限制输入字数,并提示剩余字数
- C#相关时间DateTime格式化
- C# 枚举运用";位";操作和";或";操作
- 製程能力介紹(SPC introduction) ─ 製程能力改善及評估
- 从Android源码修改cpu信息
- 升级Jenkins版本
- 『MySQL』时间戳转换
- MySQL------报错Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:NO)解决方法
- 面经:Bloomberg Internship第一轮
- BinarySearch
- 如何使用 Visual C# 2005 或 Visual C# .NET 向 Excel 工作簿传输数据
- IE盒模型与W3C盒模型区别
- div + css 样式连接
- mongoexport
- Git使用教程(转载)
热门文章
- mysql SQL_MODE设置
- 滑屏 H5 开发实践九问
- Spring 事务管理原理探究
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(4)
- Most Powerful(ZOJ 3471状压dp)
- javascript 继承、命名空间实现分享
- openfl关于windows平台编译报错解决办法
- LeetCode题解——Roman to Integer
- JQuery插件之图片轮播插件–slideBox
- Codeforces Round #363 (Div. 1) C. LRU