0

我的输入如下所示:

save 001 Some very long string with spaces... after three dots there , is also a comma

在此之后我调用类型:

load 001

它应该给我输出:

Some very long string with spaces... after three dots there , is also a comma

我正在尝试,但似乎没有任何效果,例如:

while ((scanf("%s %s", mode, key)) != EOF) {
    if (strcmp(mode, "save") == 0) { 
        getchar();
        fgets(data, 100, stdin);
        root = save(root, key, data);
        root = balance_RBT(root, blc);
    }
    if (strcmp(mode, "load") == 0) {
        load(root, key); 
    }
}
4

1 回答 1

0

给定的输入/输出没有任何问题,其余代码类似于:

#include <stdio.h>
int main() 
{ 
  char mode[444], key[333], data[222];
  while (1)
  while ((scanf("%s %s", mode, key)) != EOF) {
    if (strcmp(mode, "save") == 0) { 
      getchar();
      fgets(data, 100, stdin);
      printf("SAVE %s %s %s\n",mode,key,data);
    //root = save(root, key, data);
    //root = balance_RBT(root, blc);
    }
   if (strcmp(mode, "load") == 0) {
     printf("LOAD %s %s\n",mode,key);
     // load(root, key); 
     }
   }
 }

因此,无论您遇到什么问题,他们都必须处理您对模式、键和数据的定义,或者树插入/搜索的实现。

于 2012-11-17T15:34:56.660 回答