XHAENEUNG 오답 관련 질문드립니다.

  • User Avatar
    cisfine

    1) 에러내용 :
    오답

    2) 질문내용 :
    해당 내용에 대해, 문제에 있는 예제나 댓글에 있는 예제를 확인하였을 때 크게 문제가 없는 것을 확인하였습니다.

    잘못 생각한 부분이 있는 것 같은데, 어떤 값을 넣었을 때 오답이 나온 것인지 확인할 수 없어

    찾는데 어려움이 있습니다. 조언주시면 정말 감사하겠습니다.

    함수설명 :
    int fnc_num(char* ); // 입력 숫자(A, B)를 변환
    int fnc_num_count(char* ); // 입력 결과(C)를 알파벳을 카운트하여 확인
    int fnc_char(int , int , char* ); // operator와 A, B의 계산 결과를 int 형태로 출력

    3) 사용 코드 :
    ~~~ c++
    #include
    #include
    #include

    int fnc_num(char* );
    int fnc_num_count(char* );
    int fnc_char(int , int , char* );

    int main(){

    int T=0;
    
    char K[20];
    char A[5+1], OP[3+1], B[5+1], C[5+1];
    int A_int=0, OP_int=0, B_int=0, C_int=0;
    
    
    scanf("%d", &T);
    
    
    for(T ; T>0; T--){
    
        scanf("%s", &A);
        scanf("%s", &OP);
    
        scanf("%s", &B);
        scanf("%s", &K);
        scanf("%s", &C);
    
        A_int   =   fnc_num(A);     
        B_int   =   fnc_num(B);
    
        OP_int  =   fnc_char(A_int, B_int, &OP[0]);
    
        C_int   =   fnc_num_count(C);
    
        if(OP_int == C_int && (C_int>=0 && C_int <= 10))
            printf("Yes\n");
        else
            printf("No\n");
    
    }
    
    return 0;
    

    }

    int fnc_num(char A[5+1]){
    // one, two, three, four, five, six, seven, eight, nine, ten

    // 코드 개선방안
    // char init[11][5+1]={"zero", "one", ...};
    
    if      (strcmp(A,"zero")==0)
        return 0;
    else if (strcmp(A,"one")==0)
        return 1;
    else if (strcmp(A,"two")==0)
        return 2;
    else if (strcmp(A,"three")==0)
        return 3;
    else if (strcmp(A,"four")==0)
        return 4;
    else if (strcmp(A,"five")==0)
        return 5;
    else if (strcmp(A,"six")==0)
        return 6;
    else if (strcmp(A,"seven")==0)
        return 7;
    else if (strcmp(A,"eight")==0)
        return 8;
    else if (strcmp(A,"nine")==0)
        return 9;
    else if (strcmp(A,"ten")==0)
        return 10;
    else
        return -100;
    

    }

    int fnc_num_count(char A[5+1]){
    // one, two, three, four, five, six, seven, eight, nine, ten
    int i, j;
    int count[27] = {0};
    int count_sum = 0;

    for(i = 0; i<5; i++){
        for(j = 0; j<26; j++){
            if(A[i] == 'a'+j){
                count[j+0]  += 1;
                count_sum   += 1;
            }           
        }
    }
    
    if          (count['z'-97] == 1 && count['e'-97] == 1 && count['r'-97] == 1 && count['o'-97] == 1                       && count_sum == 4)
        return 0;           
    else if     (count['o'-97] == 1 && count['n'-97] == 1 && count['e'-97] == 1                                             && count_sum == 3)
        return 1;           
    else if     (count['t'-97] == 1 && count['w'-97] == 1 && count['o'-97] == 1                                             && count_sum == 3)
        return 2;
    else if     (count['t'-97] == 1 && count['h'-97] == 1 && count['r'-97] == 1 && count['e'-97] == 2                       && count_sum == 5)
        return 3;
    else if     (count['f'-97] == 1 && count['o'-97] == 1 && count['u'-97] == 1 && count['r'-97] == 1                       && count_sum == 4)
        return 4;
    else if     (count['f'-97] == 1 && count['i'-97] == 1 && count['v'-97] == 1 && count['e'-97] == 1                       && count_sum == 4)
        return 5;   
    else if     (count['s'-97] == 1 && count['i'-97] == 1 && count['x'-97] == 1                                             && count_sum == 3)
        return 6;
    else if     (count['s'-97] == 1 && count['e'-97] == 2 && count['v'-97] == 1 && count['n'-97] == 1                       && count_sum == 5)
        return 7;
    else if     (count['e'-97] == 1 && count['i'-97] == 1 && count['g'-97] == 1 && count['h'-97] == 1 && count['t'-97] == 1 && count_sum == 5)
        return 8;
    else if     (count['n'-97] == 2 && count['i'-97] == 1 && count['e'-97] == 1                                             && count_sum == 4)
        return 9;
    else if     (count['t'-97] == 1 && count['e'-97] == 1 && count['n'-97] == 1                                             && count_sum == 3)
        return 10;
    else 
        return -100;
    

    }

    int fnc_char(int A1, int A2, char A[1]){
    // + - *
    if (A[0] == '+')
    return A1+A2;
    else if (A[0] == '-')
    return A1-A2;
    else if (A[0] == '*')
    return A1*A2;
    else
    return -100;
    }
    ~~~


    9년 전
4개의 댓글이 있습니다.
  • User Avatar
    Corea

    아래 입력은 어떤가요?

    1
    one + two = threeeeee


    9년 전 link
  • User Avatar
    cisfine

    감사합니다.
    해당 결과에 대한 알고리즘이 잘못되어있었습니다.
    하지만 수정후에(답이 No)가 나오게 한 뒤)도 마찬가지로 오류가 나옵니다.


    9년 전 link
  • User Avatar
    Corea

    이 입력은 어떤가요?

    2
    one + two = threeeeee
    one + two = three


    9년 전 link
  • User Avatar
    cisfine

    감사합니다..! 초기화 문제였군요..
    결과를 중간중간 확인할 때 %s 형식으로만 하다보니 전체가 제대로 초기화되어있는지 확인하지 못했습니다.


    9년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.