번역해서 다시 올립니다. 도움좀 부탁드려요ㅠㅠ
보람
질문 제목 :
아래 펑션중에 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++;
}
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692451 | 이 문제좀 풀어주세요 ^^ | 게자리 | 2025-04-23 |
2692424 | 2차원배열 자료입력질문이요! (1) | 똘끼 | 2025-04-22 |
2692401 | 유닉스안에서 C언어를 이용한 명함 만들기 입니다; 이해안가는 부분이있네요 | 2gether | 2025-04-22 |
2692374 | 고수님들 댓글 마니부탁해요!!! (2) | 엄지 | 2025-04-22 |
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |