ural 2046 The First Day at School
2015-10-10 18:47
405 查看
Time limit: 1.0 second
Memory limit: 64 MB
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.
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.
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).
Problem Author: Oleg Dolgorukov
Problem Source: Ural Sport Programming Championship 2015
Tags: none (
一道模拟题。。
debug了四小时。。
#include<bits/stdc++.h>
using namespace std;
vector<string>tu[100];
vector<string>th[100];
vector<string>sa[100];
int main()
{
int n;
char name[1000],str[1000];
string s[100],w;
int m,i,j;
while(~scanf("%d",&n))
{
for(i=0; i<50; i++)
{
tu[i].clear();
th[i].clear();
sa[i].clear();
}
while(n--)
{
int tot=1;
scanf("%s",name);
int l=strlen(name);
s[tot]+=name;
while(getchar()!='\n')
{
scanf("%s",name);
l+=strlen(name);
if(l+1>10)
s[++tot]=name,l=strlen(name);
else
s[tot]+=" ",s[tot]+=name,l++;
}
// cout<<s[tot]<<endl;
cin>>w>>m;
if(w=="Tuesday")
{
for(i=1; i<=tot; i++)
tu[m].push_back(s[i]);
}
else if(w=="Thursday")
{
for(i=1; i<=tot; i++)
th[m].push_back(s[i]);
}
else if(w=="Saturday")
{
for(i=1; i<=tot; i++)
sa[m].push_back(s[i]);
}
for(i=1; i<=tot; i++)
s[i].clear();
}
int ss[10];
int l1,l2,l3,k;
ss[1]=max(tu[1].size(),max(th[1].size(),sa[1].size()));
ss[2]=max(tu[2].size(),max(th[2].size(),sa[2].size()));
ss[3]=max(tu[3].size(),max(th[3].size(),sa[3].size()));
ss[4]=max(tu[4].size(),max(th[4].size(),sa[4].size()));
// printf("%d %d %d %d\n",ss[1],ss[2],ss[3],ss[4]);
for(j=1; j<=4; j++)
{
l1=tu[j].size();
l2=th[j].size();
l3=sa[j].size();
printf("+----------+----------+----------+\n");
if(!l1&&!l2&&!l3)
printf("| | | |\n");
for(i=0; i<ss[j]; i++)
{
cout<<"|";
char ss1[151];
// cout<<l1<<" "<<l2<<" "<<l3<<endl;
if(l1)
{
l1--;
for(k=0; k<tu[j][i].size(); k++)
{
ss1[k]=tu[j][i][k];
}
ss1[tu[j][i].size()]=0;
printf("%s",ss1);
for(k=0; k<10-tu[j][i].size(); k++)
printf(" ");
}
else
{
// for(k=0; k<tu[j][i].size(); k++)
// {
// ss1[k]=tu[j][i][k];
// }
// ss1[tu[j][i].size()]=0;
// printf("%s",ss1);
for(k=0; k<10; k++)
printf(" ");
}
cout<<"|";
char ss2[151];
if(l2)
{
l2--;
for(k=0; k<th[j][i].size(); k++)
{
ss2[k]=th[j][i][k];
}
ss2[th[j][i].size()]=0;
printf("%s",ss2);
for(k=0; k<10-th[j][i].size(); k++)
printf(" ");
}
else
{
// for(k=0; k<th[j][i].size(); k++)
// {
// ss2[k]=th[j][i][k];
// }
// ss2[th[j][i].size()]=0;
// printf("%s",ss2);
for(k=0; k<10; k++)
printf(" ");
}
cout<<"|";
char ss3[151];
if(l3)
{
l3--;
for(k=0; k<sa[j][i].size(); k++)
{
ss3[k]=sa[j][i][k];
}
ss3[sa[j][i].size()]=0;
printf("%s",ss3);
for(k=0; k<10-sa[j][i].size(); k++)
printf(" ");
}
else
{
// for(k=0; k<sa[j][i].size(); k++)
// {
// ss3[k]=sa[j][i][k];
// }
// ss3[sa[j][i].size()]=0;
// printf("%s",ss3);
for(k=0; k<10; k++)
printf(" ");
}
cout<<"|"<<endl;
}
}
printf("+----------+----------+----------+\n");
}
return 0;
}
Memory limit: 64 MB
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 correspondto 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 | output |
---|---|
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 | +----------+----------+----------+ |Maths |Chemistry |History | +----------+----------+----------+ | |Modeling |Physical | | | |education | +----------+----------+----------+ | |Physics | | +----------+----------+----------+ |Urban |Biology |Astronomy | |geography | | | +----------+----------+----------+ |
Problem Source: Ural Sport Programming Championship 2015
Tags: none (
一道模拟题。。
debug了四小时。。
#include<bits/stdc++.h>
using namespace std;
vector<string>tu[100];
vector<string>th[100];
vector<string>sa[100];
int main()
{
int n;
char name[1000],str[1000];
string s[100],w;
int m,i,j;
while(~scanf("%d",&n))
{
for(i=0; i<50; i++)
{
tu[i].clear();
th[i].clear();
sa[i].clear();
}
while(n--)
{
int tot=1;
scanf("%s",name);
int l=strlen(name);
s[tot]+=name;
while(getchar()!='\n')
{
scanf("%s",name);
l+=strlen(name);
if(l+1>10)
s[++tot]=name,l=strlen(name);
else
s[tot]+=" ",s[tot]+=name,l++;
}
// cout<<s[tot]<<endl;
cin>>w>>m;
if(w=="Tuesday")
{
for(i=1; i<=tot; i++)
tu[m].push_back(s[i]);
}
else if(w=="Thursday")
{
for(i=1; i<=tot; i++)
th[m].push_back(s[i]);
}
else if(w=="Saturday")
{
for(i=1; i<=tot; i++)
sa[m].push_back(s[i]);
}
for(i=1; i<=tot; i++)
s[i].clear();
}
int ss[10];
int l1,l2,l3,k;
ss[1]=max(tu[1].size(),max(th[1].size(),sa[1].size()));
ss[2]=max(tu[2].size(),max(th[2].size(),sa[2].size()));
ss[3]=max(tu[3].size(),max(th[3].size(),sa[3].size()));
ss[4]=max(tu[4].size(),max(th[4].size(),sa[4].size()));
// printf("%d %d %d %d\n",ss[1],ss[2],ss[3],ss[4]);
for(j=1; j<=4; j++)
{
l1=tu[j].size();
l2=th[j].size();
l3=sa[j].size();
printf("+----------+----------+----------+\n");
if(!l1&&!l2&&!l3)
printf("| | | |\n");
for(i=0; i<ss[j]; i++)
{
cout<<"|";
char ss1[151];
// cout<<l1<<" "<<l2<<" "<<l3<<endl;
if(l1)
{
l1--;
for(k=0; k<tu[j][i].size(); k++)
{
ss1[k]=tu[j][i][k];
}
ss1[tu[j][i].size()]=0;
printf("%s",ss1);
for(k=0; k<10-tu[j][i].size(); k++)
printf(" ");
}
else
{
// for(k=0; k<tu[j][i].size(); k++)
// {
// ss1[k]=tu[j][i][k];
// }
// ss1[tu[j][i].size()]=0;
// printf("%s",ss1);
for(k=0; k<10; k++)
printf(" ");
}
cout<<"|";
char ss2[151];
if(l2)
{
l2--;
for(k=0; k<th[j][i].size(); k++)
{
ss2[k]=th[j][i][k];
}
ss2[th[j][i].size()]=0;
printf("%s",ss2);
for(k=0; k<10-th[j][i].size(); k++)
printf(" ");
}
else
{
// for(k=0; k<th[j][i].size(); k++)
// {
// ss2[k]=th[j][i][k];
// }
// ss2[th[j][i].size()]=0;
// printf("%s",ss2);
for(k=0; k<10; k++)
printf(" ");
}
cout<<"|";
char ss3[151];
if(l3)
{
l3--;
for(k=0; k<sa[j][i].size(); k++)
{
ss3[k]=sa[j][i][k];
}
ss3[sa[j][i].size()]=0;
printf("%s",ss3);
for(k=0; k<10-sa[j][i].size(); k++)
printf(" ");
}
else
{
// for(k=0; k<sa[j][i].size(); k++)
// {
// ss3[k]=sa[j][i][k];
// }
// ss3[sa[j][i].size()]=0;
// printf("%s",ss3);
for(k=0; k<10; k++)
printf(" ");
}
cout<<"|"<<endl;
}
}
printf("+----------+----------+----------+\n");
}
return 0;
}