⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auxil.cpp

📁 数据结构与程序设计教材源码 数据结构与程序设计教材源码
💻 CPP
字号:
 
double get_num(const char *temp)
{
   char *p = (char *) temp;
   double value;
   double sign = 1.0;
   if (*p == '-') {
      sign = -1.0;
      p++;
   }
   value = *(p++) - '0';
   while ('0' <= *p && *p <= '9') value = 10.0 * value + *(p++) - '0';
   if (*p == '.') {
      p++;
      double junk = 0.1;
      while ('0' <= *p && *p <= '9') {
         value = value + junk * (*(p++) - '0');
         junk /= 10.0;
      }
   }
   value = sign * value;
   return value;
}
 
Error_code read_num(double &x)
{
   Error_code result = success;
   int z;
   String s = read_in(cin, z);
   const char *temp = s.c_str();
   char *p = (char *) temp;
   while (*p == ' ') p++;
   if (('0' <= *p && *p <= '9') || (*p == '-')) x = get_num(p);
   else result = fail;
   return result;
}
 
Error_code get_word(const String &s, int n, String &t)
{
   if (n < 0) return fail;
   const char *temp = s.c_str();
   char *q = (char *) temp;
   char *p;
   while (n-- >= 0) {
      while (*q == ' ') q++;
      if (*q == '\0') return fail;
      p = q;
      while (*q != '\0' && *q != ' ') q++;
   }
   char old = *q;
   *q = '\0';
   t = p;
   *q = old;
   return success;
}
 
void add_spaces(String &s)
{
   const char *temp = s.c_str();
   char *new_temp = new char[3 * strlen(temp) + 1];
   char *q = (char *) temp;
   char *p = new_temp;
   while (*q != '\0') {
      if (('a' <= *q && *q <= 'z') ||
          ('A' <= *q && *q <= 'Z') ||
          ('0' <= *q && *q <= '9') ||
          *q == '.')  *(p++) = *(q++);
      else {
         *(p++) = ' ';
         *(p++) = *(q++);
         *(p++) = ' ';
      }
   }
   *p = '\0';
   s = (String) new_temp;
   delete []new_temp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -