51:方法太笨了,容我想出来简单的再更新。
#include<iostream>
#include<string>
using namespace std;
class data
{
public:
data(const string &data_str)
{
string interval(", /");
auto beg = data_str.begin(),
end = data_str.end();
string::size_type pos_first,
pos_last;
//找出间隔位置
pos_first = data_str.find_first_of(interval);
pos_last = data_str.find_last_of(interval);
//将字符串分割开
string month_str(beg, beg + pos_first);
string day_str(beg + pos_first + 1, beg + pos_last);
string year_str(beg + pos_last + 1, end);
//年与日可以直接得到
year = stoi(year_str);
day = stoi(day_str);
//判断月份,假设输入的都是正确格式
string month_bank("JanFebMarAprMayJunJulAugSepOctNovDec");
if (month_str.size() < 3) //数字形式
month = stoi(month_str);
else //单词形式
for (int i = 0; i < 12; ++i)
if (month_bank.compare(i * 3, 3, month_str, 0, 3) == 0)
{
month = i + 1;
break;
}
}
void show()
{
cout << "year: " << year << ends << "month: " << month << ends << "day: " << day << endl;
}
private:
unsigned year = 0;
unsigned month = 0;
unsigned day = 0;
};
void main()
{
data time1("December/3/1900");
time1.show();
data time2("Dec,3,1900");
time2.show();
data time3("12 3 1900");
time3.show();
system("pause");
}
结果:
year: 1900 month: 12 day: 3
year: 1900 month: 12 day: 3
year: 1900 month: 12 day: 3
请按任意键继续. . .
52:[注]暂时还没有好思路,把我收藏的博主解答贴上来大家看一看,链接在下面。
知识点:
1:stack栈,queue队列,priority_queue优先队列,是标准库的三个顺序容器适配器,书上说的非常的抽象,其实就是接收一种容器,但是操作行为不像该容器了。会需要数据结构的相关知识,建议进行了解。
2:stack栈适配器有其特有操作,pop()—删除栈顶元素、push()—将元素压栈表示其进出栈操作,top()返回栈顶元素,但不弹出。先进后出。
3:queue和priority_queue操作类似,注意该pop()和push()等操作与stack不同。先进先出。
但是题目的描述看着有些迷惑,将括号中的内容弹出不难,但是怎样转换为表达式算出其值?
原文:https://blog.csdn.net/misayaaaaa/article/details/57075149?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!