本博客仅供个人记录学习上遇到的问题和复盘
这道题做了好久,调试了好久。其实也就是将日期转换成二进制字符串,然后判断二进制字符串是否是回文串。其中有一些坑,比如stream的重置流的标志状态(注意不是清空流),还有日期月份小于10得加多0等。
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
//注意stream的重置标记位,和月份和日期少于10的处理
// bool jude(int key)//判断回文
// {
// int num = key;
// int key1 = 0;
// vector<int> v;
// while(num != 0)
// {
// v.push_back(num % 10);
// num /= 10;
// }
// int time = 0;//标记位数
// for (vector<int>::iterator i = v.end() - 1; i != v.begin() - 1;--i)
// {
// key1 += *i * pow(10, time++);
// }
// // cout << key1 << endl;
// return key == key1;
// }
string reversed(string target)
{
string target2 = "";
for (int i = target.size() - 1; i >= 0; --i)//有个\0
{
target2 += target[i];
}
return target2;
}
// int tr10(string target)
// {
// }
string tr2(int target)
{
vector<int> v;
while (target != 0)
{
v.push_back(target % 2);
target /= 2;
}
string target2 = "";
for (vector<int>::iterator i = v.begin(); i != v.end(); ++i)
{