Wenwen doesn't like English. There are too many names in English! Months have names (January, February, ...), days of the week have names (Sunday, Monday, ...), and even coins have names (Penny, Dime, ...).
Today she got confused again by a bunch of "Sunday, Monday, whatever day." Can you help him convert them into numbers?
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The input consists of only one line containing the string to be converted. | If the input is one of the following strings: "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday," please convert them to integers 0, 1, 2, 3, 4, 5, 6 respectively. If the input is not one of these strings, please output "error." |
Sunday | 0 |
Twosday | error |
Thought Process
Use a Map to store the index value for each day of the week. If the string read does not have a value in the Map (i.e., if there is no value, it will return 0), output "error"; otherwise, output the value from the Map.
Sample Code-ZeroJudge L960: Which Day?
#include <iostream>
#include <map>
using namespace std;
int main() {
map<string, int>MAP;
MAP["Sunday"] = 1;
MAP["Monday"] = 2;
MAP["Tuesday"] = 3;
MAP["Wednesday"] = 4;
MAP["Thursday"] = 5;
MAP["Friday"] = 6;
MAP["Saturday"] = 7;
string str;
cin >> str;
if (MAP[str] != 0) cout << MAP[str]-1 << endl;
else cout << "error" << endl;
}
//ZeroJudge L960
//Dr. SeanXD