題意:一個人要從一個地方到另一個地方,週末跟平時走的路程不一樣。問最少走多少天。
思路:取模就可以了。看到題目的數據有點大,小數點最多三位,就想着將數據乘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;
}