POJ1209 HDU1637 UVA158 Calendar【日期计算+模拟】

708 篇文章 18 订阅
509 篇文章 6 订阅

Calendar

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 826 Accepted: 128

Description

Most of us have a calendar on which we scribble details of important events in our lives--visits to the dentist, the Regent 24 hour book sale, Programming Contests and so on. However there are also the fixed dates: partner's birthdays, wedding anniversaries and the like; and we also need to keep track of these. Typically we need to be reminded of when these important dates are approaching--the more important the event, the further in advance we wish to have our memories jogged. 


Write a program that will provide such a service. The input will specify the year for which the calendar is relevant (in the range 1901 to 1999). Bear in mind that, within the range specified, all years that are divisible by 4 are leap years and hence have an extra day (February 29th) added. The output will specify ``today's'' date, a list of forthcoming events and an indication of their relative importance. 

Input

The first line of input will contain an integer representing the year (in the range 1901 to 1999). This will be followed by a series of lines representing anniversaries or days for which the service is requested. 

An anniversary line will consist of the letter `A'; three integer numbers (D, M, P) representing the date, the month and the importance of the event; and a string describing the event, all separated by one or more spaces. P will be a number between 1 and 7 (both inclusive) and represents the number of days before the event that the reminder service should start. The string describing the event will always be present and will start at the first non-blank character after the priority. 

A date line will consist of the letter `D' and the date and month as above. 

All anniversary lines will precede any date lines. No line will be longer than 255 characters in total. The file will be terminated by a line consisting of a single #. 

Output

Output will consist of a series of blocks of lines, one for each date line in the input. Each block will consist of the requested date followed by the list of events for that day and as many following days as necessary. 

The output should specify the date of the event (D and M), right justified in fields of width 3, and the relative importance of the event. Events that happen today should be flagged as shown below, events that happen tomorrow should have P stars, events that happen the day after tomorrow should have P-1 stars, and so on. If several events are scheduled for the same day, order them by relative importance (number of stars,if several events happen today,they are all have the same importance). 

If there is still a conflict, order them by their appearance in the input stream. Follow the format used in the example below. Leave 1 blank line between blocks.

Sample Input

1993
A 23 12 5 Partner's birthday
A 25 12 7    Christmas
A 20 12 1 Unspecified Anniversary
D 20 12
#

Sample Output

Today is: 20 12
 20 12 *TODAY* Unspecified Anniversary
 23 12 ***     Partner's birthday
 25 12 ***     Christmas

Source

New Zealand 1993 Division I,uva 158

 

问题链接POJ1209 HDU1637 UVA158 Calendar

问题描述:(略)

问题分析

  有关日期计算的题,也可以算是一个模拟题。逻辑繁琐细节多,需要耐心。

程序说明

  HDU1637和UVA158的输出格式与POJ1209略有不同,是间隔空行。POJ1209则最后的空行可有可无。

参考链接:(略)

题记:(略)

 

AC的C++语言程序如下:

/* POJ1209 HDU1637 UVA158 Calendar */

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>

using namespace std;

int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leapyear(int year)
{
    return ( ((year%4==0) && (year%100!=0)) || (year%400==0) ) ? 1 : 0;
}

struct Event {
    int id;
    int day, month, r, t;
    char name[300];
    bool operator<(const Event &pos) const {
        if(t != pos.t)
            return t < pos.t;
        else if(r != pos.r)
            return r > pos.r;
        else
            return id < pos.id;
    }
};
vector<Event> de[366];

int main()
{
    int year, id = 1;
    scanf("%d", &year);

    days[2] += leapyear(year);
    for(int i = 2; i <= 12; i++)
        days[i] += days[i - 1];

    bool flag = false;
    char op;
    while((op = getchar()) && op != '#') {
        if(op == 'A') {
            int d, m, p;
            char s[300];
            scanf("%d%d%d",&d,&m,&p);
            gets(s);
            int start = 0;
            while(s[start] == ' ')
                start++;
            for(int i = max(1, days[m - 1] + d - p); i <= days[m - 1] + d; i++) {
                Event e;
                e.id = id;
                e.day = d;
                e.month = m;
                strcpy(e.name, s + start);
                if(i != days[m - 1] + d) // 星号
                    e.r = p - (days[m - 1] + d - i - 1);
                else
                    e.r=8;
                e.t = days[m - 1] + d;
                de[i].push_back(e);
            }
            for(int i=days[12]+days[m-1]+d-p;i<=days[12];i++) {
                Event e;
                e.id = id;
                e.day = d;
                e.month = m;
                strcpy(e.name, s + start);
                e.r = p - (days[m - 1] + d - 1 + days[12] - i);
                e.t = days[m - 1] + d + days[12];
                de[i].push_back(e);
            }
            id++;
        } else if(op == 'D') {
            if(flag)
                printf("\n");
            else {
                flag = true;
                for(int i = 0; i <= days[12]; i++)
                    sort(de[i].begin(), de[i].end());
            }
            int d, m;
            scanf("%d%d", &d, &m);
            printf("Today is:%3d%3d\n", d, m);
            for(int i = 0; i < (int)de[days[m - 1] + d].size(); i++) {
                printf("%3d%3d ", de[days[m - 1] + d][i].day, de[days[m - 1] + d][i].month);
                if(de[days[m - 1] + d][i].t == days[m - 1] + d)
                    printf("*TODAY*");
                else {
                    for(int j = 0; j < de[days[m - 1] + d][i].r; j++)
                        printf("*");
                    for(int j = de[days[m - 1] + d][i].r+1; j < 8; j++)
                        printf(" ");
                }
                printf(" %s\n", de[days[m - 1] + d][i].name);
            }
        }
    }

    return 0;
}

 

AC的C++语言程序(POJ1209)如下:

/* POJ1209 Calendar */

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>

using namespace std;

int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leapyear(int year)
{
    return ( ((year%4==0) && (year%100!=0)) || (year%400==0) ) ? 1 : 0;
}

struct Event {
    int id;
    int day, month, r, t;
    char name[300];
    bool operator<(const Event &pos) const {
        if(t != pos.t)
            return t < pos.t;
        else if(r != pos.r)
            return r > pos.r;
        else
            return id < pos.id;
    }
};
vector<Event> de[366];

int main()
{
    int year, id = 1;
    scanf("%d", &year);

    days[2] += leapyear(year);
    for(int i = 2; i <= 12; i++)
        days[i] += days[i - 1];

    bool flag = false;
    char op;
    while((op = getchar()) && op != '#') {
        if(op == 'A') {
            int d, m, p;
            char s[300];
            scanf("%d%d%d",&d,&m,&p);
            gets(s);
            int start = 0;
            while(s[start] == ' ')
                start++;
            for(int i = max(1, days[m - 1] + d - p); i <= days[m - 1] + d; i++) {
                Event e;
                e.id = id;
                e.day = d;
                e.month = m;
                strcpy(e.name, s + start);
                if(i != days[m - 1] + d) // 星号
                    e.r = p - (days[m - 1] + d - i - 1);
                else
                    e.r=8;
                e.t = days[m - 1] + d;
                de[i].push_back(e);
            }
            for(int i=days[12]+days[m-1]+d-p;i<=days[12];i++) {
                Event e;
                e.id = id;
                e.day = d;
                e.month = m;
                strcpy(e.name, s + start);
                e.r = p - (days[m - 1] + d - 1 + days[12] - i);
                e.t = days[m - 1] + d + days[12];
                de[i].push_back(e);
            }
            id++;
        } else if(op == 'D') {
            if(!flag) {
                flag = true;
                for(int i = 0; i <= days[12]; i++)
                    sort(de[i].begin(), de[i].end());
            }
            int d, m;
            scanf("%d%d", &d, &m);
            printf("Today is:%3d%3d\n", d, m);
            for(int i = 0; i < (int)de[days[m - 1] + d].size(); i++) {
                printf("%3d%3d ", de[days[m - 1] + d][i].day, de[days[m - 1] + d][i].month);
                if(de[days[m - 1] + d][i].t == days[m - 1] + d)
                    printf("*TODAY*");
                else {
                    for(int j = 0; j < de[days[m - 1] + d][i].r; j++)
                        printf("*");
                    for(int j = de[days[m - 1] + d][i].r+1; j < 8; j++)
                        printf(" ");
                }
                printf(" %s\n", de[days[m - 1] + d][i].name);
            }
            printf("\n");
        }
    }

    return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这个问题属于技术问题。以下是一个简单的Python模拟登录POJ提交代码并抓取评测结果的代码示例: ```python import requests # 登录POJ,获取cookie def login(username, password): s = requests.Session() login_url = "http://poj.org/login" login_data = { "user_id1": username, "password1": password, "B1": "login", "url": "/" } s.post(login_url, data=login_data) return s # 提交代码 def submit_code(s, problem_id, language, source_code): submit_url = "http://poj.org/submit" submit_data = { "problem_id": problem_id, "language": language, "source": source_code } s.post(submit_url, data=submit_data) # 获取评测结果 def get_result(s, run_id): status_url = "http://poj.org/status" params = { "user_id": "", "result": "", "language": "", "top": run_id } r = s.get(status_url, params=params) table_start = r.text.find("<table cellpadding=0 cellspacing=0 border=0 width=100%>") table_end = r.text.find("</table>", table_start) table_html = r.text[table_start:table_end + 8] return table_html # 使用示例 username = "your_username" password = "your_password" problem_id = "1000" language = "G++" source_code = """ #include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; return 0; } """ s = login(username, password) submit_code(s, problem_id, language, source_code) table_html = get_result(s, "12345678") # 替换成实际提交的run id print(table_html) ``` 其中,`login`函数模拟登录POJ并返回一个`Session`对象,`submit_code`函数提交代码,`get_result`函数获取评测结果。你可以根据实际需要修改代码中的`username`、`password`、`problem_id`、`language`和`source_code`等参数,并替换`get_result`函数中的`run_id`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值