#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define NUM_CHOICES 5
#define MAX_WORD_LEN 50
#define MAX_MEANING_LEN 100
struct Word {
char word[ MAX_WORD_LEN] ;
char meaning[ MAX_MEANING_LEN] ;
} ;
void shuffleArray( int * array, int n) {
if ( n > 1 ) {
int i;
for ( i = 0 ; i < n - 1 ; i++ ) {
int j
= i
+ rand ( ) / ( RAND_MAX
/ ( n
- i
) + 1 ) ; int temp = array[ j] ;
array[ j] = array[ i] ;
array[ i] = temp;
}
}
}
void dailyWordTest( struct Word * word, char ** wrong_choices) {
int random_indices[ NUM_CHOICES] ;
char choices[ NUM_CHOICES] [ MAX_MEANING_LEN] ;
char user_answer[ 10 ] ; // 사용자 답변을 문자열로 받음
// 문제 설정
printf ( "\n \n --- choose answer!!---\n '%s'\n " , word
-> word
) ;
// 정답과 오답 선택지 생성
random_indices[ 0 ] = 0 ; // 0번 인덱스는 항상 정답으로 설정
for ( int i = 1 ; i < NUM_CHOICES; i++ ) {
random_indices[ i] = i; // 오답 선택지는 1부터 NUM_CHOICES-1까지
}
// 오답 선택지 섞기
shuffleArray( random_indices, NUM_CHOICES) ;
// 선택지 설정
for ( int i = 0 ; i < NUM_CHOICES; i++ ) {
if ( random_indices[ i] == 0 ) {
strcpy ( choices
[ i
] , word
-> meaning
) ; // 정답 설정 } else {
// 오답 선택지 설정
strcpy ( choices
[ i
] , wrong_choices
[ random_indices
[ i
] - 1 ] ) ; }
}
// 선택지 섞기
shuffleArray( random_indices, NUM_CHOICES) ;
// 선택지 출력
for ( int i = 0 ; i < NUM_CHOICES; i++ ) {
printf ( "%d. %s\n " , i
+ 1 , choices
[ i
] ) ; }
// 사용자 답변 받기
printf ( "답을 선택하세요 (1-%d): " , NUM_CHOICES
) ; scanf ( "%s" , user_answer
) ; int user_choice
= atoi ( user_answer
) ; // 정수로 변환
// 정답 확인
if ( user_choice >= 1 && user_choice <= NUM_CHOICES) {
if ( random_indices[ user_choice - 1 ] == 0 ) {
} else {
printf ( "정답은 '%s'입니다.\n " , word
-> meaning
) ; }
} else {
printf ( "잘못된 입력입니다. 1부터 %d까지의 숫자 중에서 선택해주세요.\n " , NUM_CHOICES
) ; }
}
int main( ) {
struct Word daily_word;
// 오늘의 단어와 뜻 설정
strcpy ( daily_word.
word , "His speech might ______ any fears about the war " ) ; strcpy ( daily_word.
meaning , "dispel" ) ;
// 오답 선택지 배열
char * wrong_choices[ NUM_CHOICES - 1 ] = {
"choose" , "compute" , "deduce" , "charge"
} ;
// 테스트 시작
dailyWordTest( & daily_word, wrong_choices) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8dGltZS5oPgoKI2RlZmluZSBOVU1fQ0hPSUNFUyA1CiNkZWZpbmUgTUFYX1dPUkRfTEVOIDUwCiNkZWZpbmUgTUFYX01FQU5JTkdfTEVOIDEwMAoKc3RydWN0IFdvcmQgewogICAgY2hhciB3b3JkW01BWF9XT1JEX0xFTl07CiAgICBjaGFyIG1lYW5pbmdbTUFYX01FQU5JTkdfTEVOXTsKfTsKCnZvaWQgc2h1ZmZsZUFycmF5KGludCAqYXJyYXksIGludCBuKSB7CiAgICBpZiAobiA+IDEpIHsKICAgICAgICBpbnQgaTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbiAtIDE7IGkrKykgewogICAgICAgICAgICBpbnQgaiA9IGkgKyByYW5kKCkgLyAoUkFORF9NQVggLyAobiAtIGkpICsgMSk7CiAgICAgICAgICAgIGludCB0ZW1wID0gYXJyYXlbal07CiAgICAgICAgICAgIGFycmF5W2pdID0gYXJyYXlbaV07CiAgICAgICAgICAgIGFycmF5W2ldID0gdGVtcDsKICAgICAgICB9CiAgICB9Cn0KCnZvaWQgZGFpbHlXb3JkVGVzdChzdHJ1Y3QgV29yZCAqd29yZCwgY2hhciAqKndyb25nX2Nob2ljZXMpIHsKICAgI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c3RyY3B5KGNob2ljZXNbaV0sIHdyb25nX2Nob2ljZXNbcmFuZG9tX2luZGljZXNbaV0gLSAxXSk7CiAgICAgICAgfQogICAgfQoKICAgIC8vIOyEoO2DneyngCDshJ7quLAKICAgIHNodWZmbGVBcnJheShyYW5kb21faW5kaWNlcywgTlVNX0NIT0lDRVMpOwoKICAgIC8vIOyEoO2DneyngCDstpzroKUKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTlVNX0NIT0lDRVM7IGkrKykgewogICAgICAgIHByaW50ZigiJWQuICVzXG4iLCBpICsgMSwgY2hvaWNlc1tpXSk7CiAgICB9CgogICAgLy8g7IKs7Jqp7J6QIOuLteuzgCDrsJvquLAKICAgIHByaW50Zigi64u17J2EIOyEoO2Dne2VmOyEuOyalCAoMS0lZCk6ICIsIE5VTV9DSE9JQ0VTKTsKICAgIHNjYW5mKCIlcyIsIHVzZXJfYW5zd2VyKTsKICAgIGludCB1c2VyX2Nob2ljZSA9IGF0b2kodXNlcl9hbnN3ZXIpOyAvLyDsoJXsiJjroZwg67OA7ZmYCgogICAgLy8g7KCV64u1IO2ZleyduAogICAgaWYgKHVzZXJfY2hvaWNlID49IDEgJiYgdXNlcl9jaG9pY2UgPD0gTlVNX0NIT0lDRVMpIHsKICAgICAgICBpZiAocmFuZG9tX2luZGljZXNbdXNlcl9jaG9pY2UgLSAxXSA9PSAwKSB7CiAgICAgICAgICAgIHByaW50Zigi7KCV64u17J2AICclcyfsnoXri4jri6QuXG4iKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwcmludGYoIuygleuLteydgCAnJXMn7J6F64uI64ukLlxuIiwgd29yZC0+bWVhbmluZyk7CiAgICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgICBwcmludGYoIuyemOuqu+uQnCDsnoXroKXsnoXri4jri6QuIDHrtoDthLAgJWTquYzsp4DsnZgg7Iir7J6QIOykkeyXkOyEnCDshKDtg53tlbTso7zshLjsmpQuXG4iLCBOVU1fQ0hPSUNFUyk7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgc3RydWN0IFdvcmQgZGFpbHlfd29yZDsKCiAgICAvLyDsmKTripjsnZgg64uo7Ja07JmAIOucuyDshKTsoJUKICAgIHN0cmNweShkYWlseV93b3JkLndvcmQsICJIaXMgc3BlZWNoIG1pZ2h0IF9fX19fXyBhbnkgZmVhcnMgYWJvdXQgdGhlIHdhciAiKTsKICAgIHN0cmNweShkYWlseV93b3JkLm1lYW5pbmcsICJkaXNwZWwiKTsKCiAgICAvLyDsmKTri7Ug7ISg7YOd7KeAIOuwsOyXtAogICAgY2hhciAqd3JvbmdfY2hvaWNlc1tOVU1fQ0hPSUNFUyAtIDFdID0gewogICAgICAgICJjaG9vc2UiLCAiY29tcHV0ZSIsICJkZWR1Y2UiLCAiY2hhcmdlIgogICAgfTsKCiAgICAvLyDthYzsiqTtirgg7Iuc7J6RCiAgICBkYWlseVdvcmRUZXN0KCZkYWlseV93b3JkLCB3cm9uZ19jaG9pY2VzKTsKCiAgICByZXR1cm4gMDsKfQ==