时间

求月份中有多少天

  1. bool isleap(int year)
  2. {
  3. if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
  4. return true;
  5. else
  6. return false;
  7. }
  8. int Dayofmonth(int year, int month)
  9. {
  10. return 31 - ((month == 2) ? (3 - isleap(year)) : ((month - 1) % 7 % 2));
  11. }

字符串

int 转 string

  1. void int_into_string(int val, string &str_val) {
  2. string tmp;
  3. while (val) {
  4. tmp += val % 10 + '0';
  5. val = val / 10;
  6. }
  7. for (int i = tmp.length(); i >= 0; i++) {
  8. str_val += tmp[i];
  9. }
  10. str_val += "#";
  11. }

string 转 int

  1. void string_into_int(string str, vector<int> &num) {
  2. int val = 0;
  3. for (int i = 0; i < str.length(); ++i) {
  4. if (str[i] == '#') {
  5. num.push_back(val);
  6. val = 0;
  7. } else {
  8. val = val * 10 + str[i] - '0';
  9. }
  10. }
  11. }

重载运算符

  1. friend complex operator+(const complex & A, const complex & B);
  2. friend complex operator-(const complex & A, const complex & B);
  3. friend complex operator*(const complex & A, const complex & B);
  4. friend complex operator/(const complex & A, const complex & B);
  5. friend istream & operator>>(istream & in, complex & A);
  6. friend ostream & operator<<(ostream & out, complex & A);