告诫后人(关于操作 1 的读入)
查看原帖
告诫后人(关于操作 1 的读入)
84132
昒昕楼主2022/5/9 12:35

错误的操作 1 读入如下:

void add() {
    while (true) {
        puts("Please enter the SID, CID, name and four scores. Enter 0 to finish.");
        cin >>a[++cnt].sid; //读入sid
        if (a[cnt].sid=="0") break; //sid是0,则结束操作1
        cin >>a[cnt].cid>>a[cnt].name>>a[cnt].s[0]>>a[cnt].s[1]>>a[cnt].s[2]>>a[cnt].s[3];
        if (Find(a[cnt].sid,"sid",cnt-1)!=0) {puts("Duplicated SID."); cnt--;}
    }
}

这样是不对的,不对的(大声

如果 sid 是 00,那么下次查找或排名的时候 会把 00 算进去

那么改一改?

void add() {
    while (true) {
        puts("Please enter the SID, CID, name and four scores. Enter 0 to finish.");
        string str;
        cin >>str;
        if (str=="0") break;
        a[++cnt].sid=str;
        cin >>a[cnt].cid>>a[cnt].name>>a[cnt].s[0]>>a[cnt].s[1]>>a[cnt].s[2]>>a[cnt].s[3];
        if (Find(a[cnt].sid,"sid",cnt-1)!=0) puts("Duplicated SID."); //查找到与输入一样的sid
    }
}

这样也是不对的(大声

如果查找到和输入一样的 sid,一定要删除,删除,要不然查找和排名的时候会算进去!

(我因为这个调了几个礼拜)

正确操作 11

void del(int x) {
    a[x].sid=""; a[x].cid=-1; a[x].name=""; a[x].s[0]=a[x].s[1]=a[x].s[2]=a[x].s[3]=-1;
}
void add() {
    while (true) {
        puts("Please enter the SID, CID, name and four scores. Enter 0 to finish.");
        string str;
        cin >>str;
        if (str=="0") break;
        a[++cnt].sid=str;
        cin >>a[cnt].cid>>a[cnt].name>>a[cnt].s[0]>>a[cnt].s[1]>>a[cnt].s[2]>>a[cnt].s[3];
        if (Find(a[cnt].sid,"sid",cnt-1)!=0) {puts("Duplicated SID."); del(cnt); cnt--;}
    }
}
2022/5/9 12:35
加载中...