题意:一个人要从一个地方到另一个地方,周末跟平时走的路程不一样。问最少走多少天。
思路:取模就可以了。看到题目的数据有点大,小数点最多三位,就想着将数据乘1000然后用整数计算的……没想到看别人的程序竟然直接用浮点数就过来。。自作多情了。
代码:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<algorithm>
#include<queue>
#include<vector>
#include<time.h>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long ll;
map<string,int> days;
string dn[8] = {"","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
string st;
int L;
char Line[10000];
ll speed;
ll Length;
void scan()
{
st = "";
Length = 0;
int pre = 0;
int rear = 0;
int len = strlen(Line);
int i = 0;
for(i = 0;;++i){
if(Line[i] == ' '){i++;break;}
st += Line[i];
}
for(;;++i){
if(Line[i] == ' '){i++;break;}
Length = Length *10+Line[i]-'0';
}
Length *=1000;
for(;i<len; ++i){
if(Line[i] =='.'){i++;break;}
pre = pre*10 + Line[i] - '0';
}
for(;i<len;++i){
rear = rear *10 + Line[i] - '0';
}
speed = pre*1000+rear;
}
int main()
{
// freopen("data.txt","r",stdin);
days["Monday"] = 1;days["Tuesday"] = 2;days["Wednesday"] = 3;days["Thursday"] = 4;
days["Friday"] = 5;days["Saturday"] = 6;days["Sunday"] = 7;
while(cin.getline(Line,1000)){
if(strlen(Line) == 0)break;
scan();
int start = days[st];
ll weekday = speed*8; ll weekend = speed*4;
ll oneweek = weekday*5+weekend *2;
ll remain = Length % oneweek;
while(remain>0){
if(start == 8)start = 1;
if(start <=5)remain -= weekday;
else remain -= weekend;
start ++;if(start == 8)start = 1;
}
start --;if(start == 0)start = 7;
cout<<dn[start]<<endl;
}
return 0;
}