title: woj1019 Curriculum Schedule 输入输出

date: 2020-03-19 10:43:00

categories: acm

tags: [acm,woj]

水题,处理好输入输出就可以

1 描述

New semester has begun, a lot of students are going to print out their curriculum schedules. They are using the same template, as the

following table shows:

Each student has a list of courses, and the items in the list are of this format:

COURSE_NAME: DAY TIME_SECTION CLASS_NUMBER

COURSE_NAME is the name of the course, which contains no more than 9 characters. Note, the COURSE_NAME may contains white spaces, but NO

trailing or leading white spaces.

DAY is one of the strings of ?MON?, ?TUE?, ?WED?, ?THU?, ?FRI?, respectively representing one of the workday of a week.

TIME_SECTION would be either ?Morning? or ?Afternoon?.

CLASS_NUMBER tells the course will be given in the CLASS_NUMBERth class in the morning or afternoon. If the TIME_SECTION is Morning, the

CLASS_NUMBER is less than 4, and If the TIME_SECTION is Afternoon, the CLASS_NUMBER is less than 3.

Given a list of the courses, just fill every course name to a specific blank in the schedule table.

2 输入输出

输入格式

There are several test cases. Each test case has an integer n, representing the number of courses that listing in the list. Then n lines follow,

each of which are of the form:

COURSE_NAME: DAY TIME_SECTION CLASS_NUMBER

No two different courses are arranged to the same time of the same day.

输出格式

Output the schedule table. Note, since every blank in the schedule table has 11 spaces, while the length of the course name is no more than 9. So,

you can easily put the name to the blank without any effort. Make sure the course name is written in the middle of the blank. This also can be

easily done if the length of the course name is odd. Otherwise, you can add a white space to the end of the course name, then the length of the

course name becomes an odd number.

See the sample output for more details. Print a blank line after each test case.

3 样例

样例输入

4

Algorithm: WED Morning 2

Algorithm: MON Afternoon 1

Data Base: TUE Afternoon 2

Wavelet: FRI Morning 4

2

Math: MON Morning 1

Computer: FRI Afternoon 3

4 分析

水题。这种还好,我还记得紫书uva11210 麻将那道题,才是真的难受

题意,输入课程时间,按格式输出课程表

注意课程名称居中,偶数在末尾添加空格

COURSE_NAME: DAY TIME_SECTION CLASS_NUMBER

只有课程名因为中间有特殊的空格需要处理一下

两个记录数组,一个记录是否在day class有课

一个记录课名

上下午的处理:如果是下午直接+4

因为输出 是按行,所以记录数组应该是[classnum][day]的形式

5 code


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n; string name[7][5];
bool exist[7][5];
string tmp,tmp2;
char day[5],timesec[15];
int classnum,date,i,j,k,len,space; int main(){
while(cin>>n){
memset(exist,0,sizeof(exist));
while(n-->0){
cin>>tmp;
while(tmp[tmp.size()-1]!=':'){ //我傻了,可能有多个空格!! 一开始只写了一个if
cin>>tmp2;
tmp=tmp+' '+tmp2;
}
tmp=tmp.substr(0,tmp.size()-1);
scanf("%s %s",day,timesec); //注意空格
scanf("%d",&classnum);
if(timesec[0]=='A')
classnum+=4;
classnum--;
if(day[1]=='O')
date=0;
else if(day[1]=='U') //一开始少打一个=...
date=1;
else if(day[1]=='E')
date=2;
else if(day[1]=='H')
date=3;
else
date=4;
exist[classnum][date]=true;
name[classnum][date]=tmp;
//cout<<classnum<<date<<tmp<<endl;
}
printf("+-----+-----------+-----------+-----------+-----------+-----------+\n"
"| | MON | TUE | WED | THU | FRI |\n"
"+-----+-----------+-----------+-----------+-----------+-----------+\n"
"| Morning |\n"
"+-----+-----------+-----------+-----------+-----------+-----------+\n"
);
for(i=0;i<4;i++){
printf("| %d |",i+1);
for(j=0;j<5;j++){
if(exist[i][j]){
len=name[i][j].size();
if(!(len&1))
name[i][j]+=' ';
space=(11-len)/2;
for(k=0;k<space;k++)
printf(" ");
cout<<name[i][j];
for(k=0;k<space;k++)
printf(" ");
printf("|");
}
else
printf(" |");
}
printf("\n");
printf("+-----+-----------+-----------+-----------+-----------+-----------+\n");
}
printf("| Afternoon |\n"
"+-----+-----------+-----------+-----------+-----------+-----------+\n");
for(i=4;i<7;i++){
printf("| %d |",i-3);
for(j=0;j<5;j++){
if(exist[i][j]){
len=name[i][j].size();
if(!(len&1))
name[i][j]+=' ';
space=(11-len)/2;
for(k=0;k<space;k++)
printf(" ");
cout<<name[i][j];
for(k=0;k<space;k++)
printf(" ");
printf("|");
}
else
printf(" |");
}
printf("\n");
printf("+-----+-----------+-----------+-----------+-----------+-----------+\n");
}
printf("\n");
}
return 0;
} /*网上的 c版,注意输入处理回车
#include<cstdio>
#include<cstring>
using namespace std; void input(char* s){
int i=0;
char c;
getchar(); //回车的处理
while(scanf("%c",&c)&&c!=':'){
s[i]=c;
i++;
}
s[i]='\0';
} int main(){
char cou[15],coutab[7][5][15],day[5],mon[10];
int yntab[7][5];
int i,j,k,l,len,dayi,n,cnum;
while(scanf("%d",&n)==1){
memset(yntab,0,35*sizeof(int));
while(n-->0){
input(cou);
scanf("%s %s %d",&day,&mon,&cnum);
if(!strcmp(day,"MON"))
dayi=0;
else if(!strcmp(day,"TUE"))
dayi=1;
else if(!strcmp(day,"WED"))
dayi=2;
else if(!strcmp(day,"THU"))
dayi=3;
else if(!strcmp(day,"FRI"))
dayi=4;
if(!strcmp(mon,"Morning"))
cnum-=1;
else
cnum+=3;
yntab[cnum][dayi]=1;
strcpy(coutab[cnum][dayi],cou);
}
printf("+-----+-----------+-----------+-----------+-----------+-----------+\n"
"| | MON | TUE | WED | THU | FRI |\n"
"+-----+-----------+-----------+-----------+-----------+-----------+\n"
"| Morning |\n"
"+-----+-----------+-----------+-----------+-----------+-----------+\n"
);
for(i=0;i<4;i++){
printf("| %d |",i+1);
for(j=0;j<5;j++){
if(yntab[i][j]){
len=strlen(coutab[i][j]);
if(!(len&1)){
coutab[i][j][len]=' ';
len++;
coutab[i][j][len]='\0';
}
k=(11-len)/2;
for(l=0;l<k;l++)
printf(" ");
printf("%s",coutab[i][j]);
for(l=0;l<k;l++)
printf(" ");
printf("|");
}
else
printf(" |");
}
printf("\n");
printf("+-----+-----------+-----------+-----------+-----------+-----------+\n");
}
printf("| Afternoon |\n"
"+-----+-----------+-----------+-----------+-----------+-----------+\n");
for(i=4;i<7;i++){
printf("| %d |",i-3);
for(j=0;j<5;j++){
if(yntab[i][j]){
len=strlen(coutab[i][j]);
if(!(len&1)){
coutab[i][j][len]=' ';
len++;
coutab[i][j][len]='\0';
}
k=(11-len)/2;
for(l=0;l<k;l++)
printf(" ");
printf("%s",coutab[i][j]);
for(l=0;l<k;l++)
printf(" ");
printf("|");
}
else
printf(" |");
}
printf("\n");
printf("+-----+-----------+-----------+-----------+-----------+-----------+\n");
}
printf("\n");
}
return 0;
}
*/

title: woj1020 Adjacent Difference 排序

date: 2020-03-19 11:43:00

categories: acm

tags: [acm,woj,排序]

水题,排序

1 描述

An adjacent difference of a sequence is a new sequence formed by replacing every element with the difference between the element and the immediately preceding element. The first value in the new sequence remains unchanged. For example, a sequence such as (1, 3, 2, 4, 5) is transformed into (1, 3-1,2-3, 4-2, 5-4), and in this manner becomes the sequence (1, 2, -1, 2, 1). Then, we want to sort the adjacent difference of the sequence in non-decreasing order. It?s an easy job for you, isn?t it? So, please solve it quickly.

2 输入输出

输入格式

Standard input will contain multiple test cases. The first line of the input is a single integer T(1 <= T <= 50) which is the number of test cases.

For each test case, the first line contains an integer N(1 <= N <= 1000), representing the size of the sequence. The second line contains

N integers (you are ensured that the absolute value of each integer is less than ), representing the elements of this sequence.

输出格式

Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

For each test case, output one line containing n elements representing the sorted adjacent difference of the sequence. Elements are separated by one blank space.

3 样例

样例输入

1

5

1 3 2 4 5

样例输出

Case 1:

-1 1 1 2 2

4 code

// 先计算差,再排序
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int T,S,tmp;
vector<int>nums;
vector<int>ans;
int main(){
cin>>T;
int casee=0;
while(casee<T){
nums.clear();
ans.clear(); //每次清空
if(casee!=0)
cout<<endl;
casee++;
cin>>S;
cin>>tmp;
nums.push_back(tmp);
ans.push_back(tmp);
S--;
while(S--)
{
cin>>tmp;
nums.push_back(tmp);
tmp=tmp-nums[nums.size()-2];
ans.push_back(tmp);
}
sort(ans.begin(),ans.end());
printf("Case %d:\n",casee);
for(int i=0;i<nums.size()-1;i++){
cout<<ans[i]<<' ';
}
cout<<ans[ans.size()-1]<<endl;
}
//system("pause");
return 0;
} // sort 自己写快排
//list vector 数组模拟list https://blog.csdn.net/stormdpzh/article/details/8836268
// 学习笔记 https://blog.csdn.net/stormdpzh

woj1019 Curriculum Schedule 输入输出 woj1020 Adjacent Difference 排序的更多相关文章

  1. STL基础--算法(已排序数据的算法,数值算法)

    已排序数据的算法 Binary search, merge, set operations 每个已排序数据算法都有一个同名的更一般的形式 vector vec = {8,9,9,9,45,87,90} ...

  2. STL详解

    STL概貌                                                                                                ...

  3. 【转载】algorithm、numeric、functional

    reference url:http://www.cplusplus.com/reference/algorithm reference url:https://blog.csdn.net/Swust ...

  4. c语言程序设计案例教程(第2版)笔记(一)—零散、输入输出、最小公倍数、选择排序、冒泡排序

    零散知识点: 非格式化输入输出:getchar().putchar() 格式化输入输出   :scanf().printf() 字符串输入输出   :gets() 或 scanf().puts() 或 ...

  5. XMU 1040 Schedule 【拓扑排序】

    1040: Schedule Time Limit: 500 MS  Memory Limit: 64 MBSubmit: 12  Solved: 2[Submit][Status][Web Boar ...

  6. LeetCode 210. Course Schedule II(拓扑排序-求有向图中是否存在环)

    和LeetCode 207. Course Schedule(拓扑排序-求有向图中是否存在环)类似. 注意到.在for (auto p: prerequistites)中特判了输入中可能出现的平行边或 ...

  7. UVA 11462 Age Sort(计数排序法 优化输入输出)

    Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...

  8. LeetCode 207. Course Schedule(拓扑排序)

    题目 There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have p ...

  9. POJ 3553 Task schedule【拓扑排序 + 优先队列 / 贪心】

    Task schedule Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 515 Accepted: 309 Special J ...

随机推荐

  1. 敏捷史话(四):敏捷是人的天性 —— Arie van Bennekum

    敏捷是人的天性,是你与生俱来的东西.面对敏捷,Arie van Bennekum 下了这样一个结论. 但这并不意味着人们只能通过天赋获得敏捷,对于想要学习敏捷的人来说,敏捷绝不是仅仅靠学习僵化的框架. ...

  2. 删除HDFS中指定的文件。

    1 import java.text.SimpleDateFormat; 2 import java.util.Scanner; 3 4 import org.apache.hadoop.fs.Fil ...

  3. 为失败设计,大量引入对SRE的理解,鲁棒性高

    https://go-kratos.dev/#/ Principles 简单:不过度设计,代码平实简单 通用:通用业务开发所需要的基础库的功能 高效:提高业务迭代的效率 稳定:基础库可测试性高,覆盖率 ...

  4. Python_1生成器(下)之单线并行--生产着消费者模型

    1 import time 2 def consumer(name): 3 print('%s准备吃包子了!' %name) 4 while True: 5 baozi = yield 6 print ...

  5. Defining Go Modules

    research!rsc: Go & Versioning https://research.swtch.com/vgo shawn@a:~/gokit/tmp$ go get --helpu ...

  6. Java 字符串简介

    从概念上讲,Java 字符串就是 Unicode 字符序列.Java 没有内置的字符串类型,而是在标准 Java 类库中提供了一个预定义类,很自然地叫做 String.每个用双引号括起来的字符串都是 ...

  7. 2021年Web开发的7大趋势

    技术发展日新月异,所以 Web 开发人员也需要及时了解行业最新的发展趋势. 全球有超过 17.4 亿个网站.在每一个细分领域都有无数企业争夺搜索引擎的排名前列位置.开发人员应该了解和发现更多创新的 W ...

  8. mysql本地中127.0.0.1连接不上数据库怎么办

    首先在本地使用Navicat for MySQL建立一个bai数据库.在dreamweaver中建立一个PHP格式的网页,方便链接测试.测试发du现,如果zhi无法使用localhost链接mysql ...

  9. LOJ10090

    题目描述 原题来自:USACO 2005 Dec. Gold FJ 有 n 头奶牛(2<=n<=1000) ,编号为1..n .奶牛们将按照编号顺序排成一列队伍(可能有多头奶牛在同一位置上 ...

  10. office提示“应用程序无法正常启动(0xc0000142)。请单击确认关闭应用程序”

    打开word文档,突然弹出如下提示框: 网上查询,说应用程序无法正常启动(0xc0000142)的原因可能是缺少组件导致的.控制面板 - 时钟和区域 - 更改日期.时间或数字格式 - 管理 - 更改系 ...