直播

//
// Created by jihuayu on 2020/2/12.
//
#include<stdio.h>
#include<malloc.h>
#include<string.h>

const char *base_num[11] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
#define NUM_LENGTH (11)

typedef struct Var {
    char *name;
    int num;
} Var;

typedef struct Line {
    char *str;
    int pos;
} Line;

typedef struct VM {
    Var **vars;
} VM;

//从位置pos开始比较base是不是和str一样
int cmp(const char *base, const char *str, int pos) {
    for (int i = 0; i < strlen(str); ++i) {
        if (base[pos + i] != str[i] || (i + pos >= strlen(base))) {
            return 0;
        }
    }
    return 1;
}

int cn_to_num1(Line *line) {
    for (int i = 0; i < NUM_LENGTH; i++) {
        if (cmp(line->str, base_num[i], line->pos)) {
            line->pos += strlen(base_num[i]);
            return i;
        }
    }
    return -1;
}

int cn_to_num(Line *line) {
    int a1 = cn_to_num1(line);
    int a2 = cn_to_num1(line);
    if (a2 == -1) {
        return a1;
    }
    int a3 = cn_to_num1(line);
    if (a3 == -1) {
        if (a1 == 10 & a2 == 10) {
            return -1;
        }
        if (a2 == 10) {
            return a1 * 10;
        }
        if (a1 == 10) {
            return 10 + a2;
        }
    }
    if (a2 == 10) {
        return a1 * 10 + a3;
    }
    return -1;
}

char *num_to_cn(int num) {
    return "";
}

void print(char *name) {
    printf("%s", "");
}

Var *create_var(char *name, int num) {
    Var *var = (Var *) malloc(sizeof(Var));
    var->name = name;
    var->num = num;
    return var;
}

void add(VM *vm, char *name, int num) {

}


void desc(VM *vm, char *name, int num) {

}

posted @ 2020-02-12 11:39  纪华裕  阅读(235)  评论(0编辑  收藏  举报