错误的操作 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 是 0,那么下次查找或排名的时候 会把 0 算进去
那么改一改?
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,一定要删除,删除,要不然查找和排名的时候会算进去!
(我因为这个调了几个礼拜)
正确操作 1:
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--;}
}
}