번역해서 다시 올립니다. 도움좀 부탁드려요ㅠㅠ
보람
질문 제목 :
아래 펑션중에 void leaders(void); 펑션좀 부탁드릴게요.
void disqualify(*char symbol)도 정상적으로 작동은 되는데, 뭔가 사알짝 빠진거같은데 코드좀 봐주세요ㅠㅠ많이 풀긴했는데, 제힘으로 너무 역부족이네요,,
시간좀 내주시면 정말 정말 감사드릴게요
질문 내용 :
scoreboard.c: 스탠다드 아웃풋을 통해 커맨드를 읽고 다음과 같은 커맨드를 수행한다.void score(char *string int number);
플레이어의 이름 string과 점수 number를 기록한다.
output은 없고, number는 -999999999와 999999999사이의 정수이다.void best(char *string);
한줄에 best string number 식으로 output을 한다.
여기서 number는 이름 string의 지금까지의 최고점수를 뜻한다.
만약 그 플레이어의 점수가 기록되지 않았다면 number대신에 ?를 output한다.void highscore(void);
한줄에 highscore number 식으로 output을 한다.
여기서 number는 지금까지의 최고점수를 뜻한다.
만약 어떤 점수도 기록되지 않았다면 highscore ?를 output한다.void disqualify(char *symbol);
이름이 symbol 인 모든 점수들을 다 제거한다.
highscore 커맨드는 이 플레이어의 의한 점수를 다 제외할것이다.
disqualify 이후에도 score 커맨드를 통해 다시 게임에 참가할수있다.void leaders(void);
한줄에 leaders 최고득점자이름들을 output 한다.
한 사람의 이름전에는 single space를 output 한다.
이름은 ascii에서의 사전순서로 나열한다.
만약 leader가 없다면 leaders ? 를 output 한다.프로그램은 3000개의 유효 커맨드 이후나 eof 중 먼저 발생시 종료된다.
만약 input name이 20자를 초과한다면, 전체의 이름을 다 읽되 첫20자까지만 고려한다.
heap storage를 써서는 안된다.주어진 readstring.h, readstring.c: int readstring(char *s, int n);
을 통해 정수 n까지의 string c를 읽습니다.원문:https://www.student.cs.uwaterloo.ca/~cs136/assignments/a10/예제 input
score fredflintstonefrombedrock 10
score wilma 20
score fredflintstonefrombe 20
highscore
score betty 30
highscore
best fredflintstonefrombedrock
score fredflintstonefrombedrock 25
best fredflintstonefrombeyond
best barney
score a 250
score b 200
score c 300
score d 250
disqualify c
highscore
best c
leaders예제 output
highscore 20
highscore 30
best fredflintstonefrombe 20
best fredflintstonefrombe 25
best barney ?
highscore 250
best c ?
leaders a d아래는 제가 짠 코드입니다. leaders 펑션좀 도와주세요.. ㅠㅠ 나머지 위의 펑션들은 정상작동합니다!
disqualify 펑션도 뭔가 살짝 빠진거 같긴하지만..
-----------------------------------------------------------------------------------------------------------------
#include stdio.h
#include string.h
#include stdlib.h
#include stdbool.h
#include readstring.hstruct ascore{ // 이름과 점수를 저장하기위한 structure.
char name[21];
int score;
};typedef struct ascore scores[3000];scores scorelist;
scores theleaders;
int scorecount=0;void score(char *string, int number){
int i=scorecount;
strcpy(scorelist[i].name,string); //scorelist에 이름을 기록
scorelist[i].score=number; //scorelist에 점수를 기록
scorecount++; //몇번째 score 펑션 call인가
}void best(char *string){
int bestscore;
int counter=0;
printf(best %s ,string);
&nbp for (int i=scorecount;i0;i--){
if(strcmp(string,scorelist[i-1].name)==0){
bestscore = scorelist[i-1].score;
} else{
counter++;
}
}
if (counter==scorecount){
printf(?\n);
return;
}
for(int j=scorecount;j0;j--){
if(strcmp(string,scorelist[j-1].name)==0 &&
scorelist[j-1].scorebestscore){
bestscore = scorelist[j-1].score;
}
}
printf(%d\n,bestscore);
}void highscore(){
int max;
if (scorecount==0){
printf(highscore ?\n);
} else {
max=scorelist[0].score;
for (int i=scorecount;i0;i--){
if (scorelist[i-1].scoremax){
max=scorelist[i-1].score;
}
}
printf(highscore %d\n,max);
}
}void disqualify (char *symbol){
for(int i=0;iscorecount;i++){
if(strcmp(symbol,scorelist[i].name)==0){
scorelist[i]=scorelist[i+1];
}
}
}void leaders(){
int leadingscore = scorelist[0].score;
int k=0;
printf(leaders );
if (scorecount==0){
printf(?);
}
for (int i=scorecount;i0;i--){ // finding the leadingscore.
if (scorelist[i-1].scoreleadingscore){
leadingscore=scorelist[i-1].score;
}
}
for (int j=scorecount;j0;j--){ // making the list of names w/ leadingscore.
if (leadingscore==scorelist[j].score){
strcpy(theleaders[k].name,scorelist[j].name);
theleaders[k].score=scorelist[j].score;
k++;
}
}
for (int l=0;lk;l++){ // printing the names of the leaders.
printf(%s ,theleaders[l].name);
}
printf(\n);
}int main(void){
int n=0, n_command=0;
while(n_command3000){ // program processes 3000 valid commands only
char str[21];
if (scanf(%s,str)!=1) break;
if (!strcmp(str,score)){
readstring(str,20);
scanf(%d,&n);
score(str,n);
n_command++;
} else if (!strcmp(str,best)){
readstring(str,20);
best(str);
n_command++;
} else if (!strcmp(str,highscore)){
highscore();
n_command++;
} else if (!strcmp(str,disqualify)){
readstring(str,20);
disqualify(str);
n_command++;
} else if (!strcmp(str,leaders)){
leaders();
n_command++;
}
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |
2699476 | 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) | 클라우드 | 2025-06-26 |