Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大水题,注意格式,PE的注意

Posted by KatrineYang at 2016-08-06 16:01:11 on Problem 1209 and last updated at 2016-08-06 16:02:45
today is后面那个也需要保留3的宽度
另外就是相对重要度是按照从大到小而不是从小到大,我因为这个WA了一次!!!

#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

struct date{
	int month;
	int day;
	date(int m, int d): month(m), day(d){}
	date(){}
};


struct anniv{
	int month;
	int day;
	int impt;
	int bh;
	string cont;
	date getDate(){
		return date(month, day);
	}
};

bool operator<(const anniv& a1, const anniv& a2){
	if(a1.month < a2.month) return true;
	if(a1.month == a2.month && a1.day < a2.day) return true;
	if(a1.month == a2.month && a1.day == a2.day && a1.impt > a2.impt) return true;
	if(a1.month == a2.month && a1.day == a2.day && a1.impt == a2.impt && a1.bh < a2.bh) return true;
	return false;
}

bool operator>(const anniv& a1, const anniv& a2){
	return !(a1<a2);
}

vector<anniv> annivs;
vector<date> dates;
int year;

date nextDay(date now){
	date temp = now;
	temp.day ++;
	if(temp.month == 2 && (temp.day == 30 || (temp.day == 29 && year%4 != 0))){
		temp.month = 3;
		temp.day = 1;
		return temp;
	}
	if(temp.month == 1 || temp.month == 3 || temp.month == 5 || temp.month == 7 || temp.month == 8 || temp.month == 10 || temp.month == 12){
		if(temp.day == 32){
			temp.month ++;
			temp.day = 1;
			if(temp.month == 13) temp.month = 1;
			return temp;
		}
	}
	if(temp.month == 4 || temp.month == 6 || temp.month == 9 || temp.month == 11){
		if(temp.day == 31){
			temp.month ++;
			temp.day = 1;
			return temp;
		}
	}
	return temp;
}

void quickSort(vector<anniv> &s, int l, int r)
{
    if (l< r)
    {
        int i = l, j = r;
        anniv x = s[l];
        while (i < j)
        {
            while(i < j && s[j]> x) // 从右向左找第一个小于x的数
                j--;
            if(i < j)
                s[i++] = s[j];
            while(i < j && s[i]< x) // 从左向右找第一个大于等于x的数
                i++;
            if(i < j)
                s[j--] = s[i];
        }
        s[i] = x;
        quickSort(s, l, i - 1); // 递归调用
        quickSort(s, i + 1, r);
    }
}


int main() {
	string s;
	getline(cin, s);
	stringstream ss(s);
	ss >> year;
	int bh = 0;
	while(1){
		getline(cin, s);
		if(s[0] == '#') break;
		int cur = 0;
		char type = s[0]; cur ++;
		while(s[cur] == ' ') cur++;
		int Day, Month;
		char shu1 = s[cur], shu2 = s[cur+1];
		if(shu2 == ' '){
			Day = shu1 - '0';
			cur += 1;
		}
		else{
			Day = 10 * (shu1-'0') + shu2 - '0';
			cur += 2;
		}
		while(s[cur] == ' ') cur++;
		shu1 = s[cur];
		if(cur+1 < s.length()) shu2 = s[cur+1];
		else shu2 = ' ';
		if(shu2 == ' '){
			Month = shu1 - '0';
			cur += 1;
		}
		else{
			Month = 10 * (shu1-'0') + shu2-'0';
			cur += 2;
		}
		if(type == 'A'){
			anniv temp;
			temp.month = Month;
			temp.day = Day;
			while(s[cur] == ' ') cur++;
			temp.impt = s[cur] - '0';
			cur++;
			while(s[cur] == ' ') cur++;
			temp.cont = s.substr(cur);
			int len = temp.cont.length();
			int Len = len;
			for(int i = len-1; i >= 0; i--){
				if(temp.cont[i] == ' '){
					Len--;
					continue;
				}
				break;
			}
			temp.cont = temp.cont.substr(0, Len);
			temp.bh = bh;
			bh ++;
			annivs.push_back(temp);
		}
		else{
			date dtemp;
			dtemp.month = Month;
			dtemp.day = Day;
			dates.push_back(dtemp);
		}
	}
	int numOfDates = dates.size();
	int numOfAnnivs = annivs.size();
	quickSort(annivs, 0, numOfAnnivs-1);
	/*
	for(int i = 0; i < numOfAnnivs; i++){
		cout << annivs[i].day << " " << annivs[i].month << " " << annivs[i].impt << " " << annivs[i].cont << endl;
	}
	*/
	int annivBeginIdx[13][32];
	int annivNum[13][32] = {0};
	for(int i = 0; i < numOfAnnivs; i++){
		if(annivNum[annivs[i].month][annivs[i].day] == 0){
			annivBeginIdx[annivs[i].month][annivs[i].day] = i;
		}
		annivNum[annivs[i].month][annivs[i].day] ++;
	}
	for(int i = 0; i < numOfDates; i++){
		date Date = dates[i];
		printf("Today is:");
		if(Date.day < 10) printf(" ");
		printf(" %d", Date.day);
		if(Date.month < 10) printf(" ");
		printf(" %d", Date.month);
		printf("\n");
		//printf("Today is: %d %d\n", Date.day, Date.month);
		if(annivNum[Date.month][Date.day] > 0){
			int first = annivBeginIdx[Date.month][Date.day];
			int num = annivNum[Date.month][Date.day];
			vector<anniv> todayAnnivs;
			for(int j = first; j < first+num; j++){
				todayAnnivs.push_back(annivs[j]);
			}
			for(int j = 1; j < num; j++){
				for(int k = j; k > 0; k--){
					if(todayAnnivs[k].bh > todayAnnivs[k-1].bh) break;
					anniv tmp = todayAnnivs[k];
					todayAnnivs[k] = todayAnnivs[k-1];
					todayAnnivs[k-1] = tmp;
				}
			}
			for(int j = 0; j < num; j++){
				if(Date.day < 10) printf(" ");
				printf(" %d", Date.day);
				if(Date.month < 10) printf(" ");
				printf(" %d", Date.month);
				printf(" *TODAY* ");
				printf("%s\n", todayAnnivs[j].cont.c_str());
			}
		}
		date futureDate = Date;
		for(int j = 0; j <= 6; j++){
			futureDate = nextDay(futureDate);
			int num = annivNum[futureDate.month][futureDate.day];
			if(num == 0) continue;
			int first = annivBeginIdx[futureDate.month][futureDate.day];
			for(int k = first; k < first+num; k++){
				if(annivs[k].impt - j <= 0) continue;
				int relImpt = annivs[k].impt - j;
				if(futureDate.day < 10) printf(" ");
				printf(" %d", futureDate.day);
				if(futureDate.month < 10) printf(" ");
				printf(" %d ", futureDate.month);
				for(int l = 0; l < relImpt; l++) printf("*");
				for(int l = 0; l < 8-relImpt; l++) printf(" ");
				printf("%s\n", annivs[k].cont.c_str());
			}
		}
		printf("\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator