zoukankan      html  css  js  c++  java
  • URAL 2046 A

    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[50];
    
    vector<string>vi[10][10];
    
    
    void CHANGE()
    {
        int pre = 0;
        for(int i = 0 ; i < str.size() ; ++ i)
        {
            if (str[i] == ' ' ||  i == str.size() - 1 )
            {
                string t1;
                t1.clear();
                if (i == str.size() - 1) i ++;
                for(int k = pre ; k < i ; ++ k)
                {
                    t1.pb(str[k]);
                }
                name.pb(t1);
                pre = i + 1;
            }
        }
    }
    
    
    
    
    int main(int argc,char *argv[])
    {
      int n;
      memset(flag,0,sizeof(flag));
      cin >> n ;getchar();
      for(int i = 0 ; 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 = 1;
          else if(day == s2) c = 2;
          else  c = 3;
          int flag = 0;
          string tt1;
          for(int j = 0 ; j < name.size() ; ++ j)
          {
              if (tt1.size() + name[j].size() + flag > 10)
              {
                  vi[r][c].pb(tt1);
                  tt1.clear();
                  tt1 = name[j];
                  flag = 1;
              } 
              else
              {
                  if (flag == 0) flag = 1;
                  else tt1 += ' ';
                  tt1 += name[j];
              }
          }
          if (tt1.size() >= 1) vi[r][c].pb(tt1);
      }
      for(int i = 1 ; i <= 4 ; ++ i)flag[i] = 1;
      for(int i = 1 ; i <= 4 ; ++ i)
      {
          for(int j = 1 ; j <= 3 ; ++ j)
              flag[i] = max(flag[i],(int)vi[i][j].size());
      }
      cout <<"+----------+----------+----------+" <<endl;
      for(int i = 1 ; i <= 4 ; ++ i)
      {
           for(int t = 1 ; t <= flag[i] ; ++ t)
           {
               cout << "|";
               for(int j = 1 ; j <= 3 ; ++ j)
               {
                   int bg = 0;
                   if (vi[i][j].size() >= t)
                   {
                       cout << vi[i][j][t-1];
                       bg = vi[i][j][t-1].size();
                   }
                   for(int r = bg + 1 ; r <= 10 ; ++ r) cout << " ";
                   cout << "|";
               }
               cout << endl;
           }
           cout <<"+----------+----------+----------+" <<endl;
      }
      return 0;
    }
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    库引入问题
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4718876.html
Copyright © 2011-2022 走看看