C 存储和跳过输入';s-字符串

C 存储和跳过输入';s-字符串,c,string,input,C,String,Input,因此,我试图实现以下输入命令 score string number Record number as the score for the player whose name is string. No output is produced. Assume number is an integer between -999999999 and 999999999. best string Output a line containing best string number where n

因此,我试图实现以下输入命令

score string number 
Record number as the score for the player whose name is string. No output is produced. Assume number is an integer between -999999999 and 999999999.

best string 
Output a line containing best string number where number is the best score recorded so far for the player whose name is string. 
Output ? instead of number if no score has been recorded for the player.

highscore 
Output a line containing highscore number where number is the highest score recorded for any player so far. Output highscore ? if no score has been recorded.

Any command other than score, best, highscore. Ignore the command and proceed to the next one.
下面是一些示例输入/输出

Sample Input

score FredFlintstonefromBedrock 10
score Wilma 20
score FredFlintstonefromBe 20
highscore
score Betty 30
highscore
best FredFlintstonefromBedrock
score FredFlintstonefromBedrock 25
best FredFlintstonefromBeyond
best Barney

Output for Sample Input

highscore 20
highscore 30
best FredFlintstonefromBe 20
best FredFlintstonefromBe 25
best Barney ?
我给下面的函数readstring。。。如果能够成功读取字符串,则生成true。我正在考虑将分数存储在一个数组中。。。了解更多信息。我也不能使用堆存储

我的问题是我如何储存他们的名字和分数。还有,我如何区分数字和字符串

以下是我目前掌握的/PSOODOCODE:

    #include <stdio.h>
    #include <string.h>
    #include "readstring.h"


    int main(void) {
    char *i = "";  
    int x = 0;     
    char s[1000];
    char* a[100];
    int b[100];

    while (readstring(s,20) != 0) {
     //if(s == "score")
     // void; (do nothing)

     // if s is a number;
     // a[x] = i;
     // b[x] = s;
     // x++;

     //if (s == "highscore");
     // printf("highscore %d\n", (maxof b);

     //if (i == "best") {
     // printf("best %s %d\n", s, (maxof a's correspoding score);

     // else  i = s;
}
}
#包括
#包括
#包括“readstring.h”
内部主(空){
char*i=“”;
int x=0;
chars[1000];
char*a[100];
int b[100];
while(readstring(s,20)!=0){
//如果(s=“分数”)
//无效;(什么也不做)
//如果s是一个数字;
//a[x]=i;
//b[x]=s;
//x++;
//如果(s=“高分”);
//printf(“高分%d\n”,(最大分数b);
//如果(i=“最佳”){
//printf(“最佳%s%d\n”,s,(a对应分数的最大值);
//否则i=s;
}
}
我觉得上面的描述是非常错误的……有什么建议吗?:)

如何存储姓名及其分数

如果您使用的是AVL树,请在节点中存储名称和分数。根据分数对树排序。但是,名称查找将为O(n)

如何区分数字和字符串

使用stdlib.h中的
strtol

我觉得[代码]是非常错误的…有什么建议吗

不要硬编码字符串的长度。而是编写:

while (readstring(s, (sizeof s) - 1))
由于从输入中读取单个单词时没有维护状态,因此伪代码不会检测到格式错误的输入,如下所示:

score Wilma
highscore 100
best

所以我不允许使用任何堆存储,这意味着我不能使用malloc,因此没有AVL:(…我想我会将分数存储在一个数组中,但我不知道名称?有什么建议吗?