问题描述
- hdu 1497 Simple Library Management System 怎么写都不对
-
#include
#include
#include
typedef struct{
int s[9];
int sum;
}Cus;
Cus cus[1005];
int book[100005];
int main(){
int m,n;
while (scanf("%d %d",&m,&n)!=EOF)
{
memset(cus,0,sizeof(cus));
memset(book,-1,sizeof(book));
int com,i,a,b;
char ch;
scanf("%d",&com);while (com--) {getchar(); scanf("%c",&ch); if (ch=='B') { scanf("%d %d",&a,&b); if (book[b]!=-1) printf("The book is not in the library nown"); else if (cus[a].sum>=9) printf("You are not allowed to borrow any moren"); else { book[b]=a; cus[a].s[cus[a].sum]=b; cus[a].sum++; printf("Borrow successn"); } } else if (ch=='R') { scanf("%d",&b); if (book[b]==-1) printf("The book is already in the libraryn"); else { int temp; for (i=0;i<cus[book[b]].sum;i++) if (cus[book[b]].s[i]==b) { temp=i; } for (i=temp;i<cus[a].sum;i++) cus[book[b]].s[i]=cus[book[b]].s[i+1]; cus[book[b]].sum-=1; book[b]=-1; printf("Return successn"); } } else if (ch=='Q') { scanf("%d",&a); int num=cus[a].sum; if (num==0) printf("Emptyn"); else { for(i=0;i<cus[a].sum;++i) for (int j=cus[a].sum-1;j>i;--j) { int t; if (cus[a].s[i]>cus[a].s[j]) { t=cus[a].s[i]; cus[a].s[i]=cus[a].s[j]; cus[a].s[j]=t; } } for (i=0;i<cus[a].sum;i++) { printf("%d",cus[a].s[i]); if (i<cus[a].sum-1) printf(" "); else printf("n"); } } } } printf("n"); }
return 0;
}这个是我写的代码 样例都过了 根标程对照也看出来哪里错了 QAQ
球指教 为什么交了就是wa呢 QAQ
辛苦各位大神了(?Д`)附带原题连接 CSDN移动问答
时间: 2024-10-30 15:43:00