XHAENEUNG 코드 검토 부탁드립니다

  • ahn
    ahn
    // ConsoleApplication4.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
    
    #include "stdafx.h"
    #include <stdio.h>
    #include <string.h>
    #include "math.h"
    #include <iostream>
    
    #define MAX(a, b)   (a) > (b) ? (a) : (b)
    #define MIN(a, b)   (a) < (b) ? (a) : (b)
    
    char buf[4096], *ex = buf + 4096, *ch = ex;
    
    using namespace std;
    
    
    inline bool read(){
        if (++ch >= ex) { ch = buf; fread(buf, 1, 4096, stdin); }
        return true;
    }
    
    inline int scan(int n = 0){
        while (read() && (*ch < '0' || *ch > '9'));
        do { n = n * 10 + *ch - '0'; } while (read() && *ch >= '0' && *ch <= '9');
        return n;
    }
    
    
    int F_cal(int left, char operato[], int right){
        int result;
    
        if (operato[0] == '+'){
            result = left + right;
    
        }
        else if (operato[0] == '-'){
            result = left - right;
        }
        else if (operato[0] == '*'){
            result = left * right;
        }
        return result;
    }
    
    
    void F_swap(char former[])
    {
        int length = strlen(former) - 1;
    
        for (int i = 0; i < length; i++){
            for (int i = 0; i < length; i++){
                if (former[i] > former[i + 1]){
                    char temp = former[i];
                    former[i] = former[i + 1];
                    former[i + 1] = temp;
                }
            }
        }
    }
    
    
    int F_examine(char array[]){
        if (!strcmp(array,"eorz")){
            return 0;
        }
    
        else if (!strcmp(array, "eno")){
            return 1;
        }
    
        else if (!strcmp(array, "otw")){
            return 2;
        }
    
        else if (!strcmp(array, "eehrt")){
            return 3;
        }
    
        else if (!strcmp(array, "foru")){
            return 4;
        }
        else if (!strcmp(array, "efiv")){
            return 5;
        }
    
        else if (!strcmp(array, "isx")){
            return 6;
        }
    
        else if (!strcmp(array, "eensv")){
            return 7;
        }
    
        else if (!strcmp(array, "eghit")){
            return 8;
        }
    
        else if (!strcmp(array, "einn")){
            return 9;
        }
    
        else if (!strcmp(array, "ent")){
            return 10;
        }
    }
    
    void F_cmp(int calculated_result, int result){
        if (calculated_result == result&& calculated_result>=0 && calculated_result<=10)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    
    int main(){
        int T;
        cin >> T;
    
        for (int testcase = 0; testcase < T; testcase++){
            char input[20] = { 0, };
    
            char left[20] = { 0, };//좌
            char oper[2] = { 0, };//연산자
            char same[2] = { 0, };//등호
            char right[20] = { 0, };//우
            char result[20] = { 0, };//결과값
    
            cin >> left; // 좌 숫자 입력
            cin >> oper; // 연산자 입력
            cin >> right; // 우 숫자 입력
            cin >> same; // 등호 입력
            cin >> result; // 결과값 입력
    
            int i = 0;
    
            F_swap(left);
            F_swap(right);
            F_swap(result); // 결과값을 알파벳 순으로 정렬 ex) treeh -> eehtr
    
            int num_left = F_examine(left); //좌숫자 알파벳을 숫자(int)로 변환 ex) three -> 3
            int num_right = F_examine(right); // 동일
            int num_result = F_examine(result); // 동일
    
            int calculated_result; 
            calculated_result = F_cal(num_left, oper, num_right); // ex) 3 + 3 계산하고 결과값인 6 반환
            F_cmp(calculated_result, num_result);// 처음 주어진 결과값과 계산으로 나온 결과값이 일치하는지 확인
        }
    
        return 0;
    }
    

    8년 전
7개의 댓글이 있습니다.
  • ahn
    ahn

    c++로 작업했구요 입력값 사이에 공백이 있다고 가정했습니다.
    댓글에 있는 입력값도 넣어보고 계산도 잘 됐는데, 알고스팟에 제출하면 오답이라고 뜹니다.
    어디가 잘못된 것인지 검토부탁드립니다!


    8년 전 link
  • pushbell7
    pushbell7

    f_swap -> for state var -> i, i


    8년 전 link
  • pushbell7
    pushbell7

    one + zero = zeroo -> Yes

    F_examine(result)-> there is not return statement
    --> it result in returning prior return value


    8년 전 link
  • pushbell7
    pushbell7

    ㅎ한ㄱ글ㅇㅇㅣ ㅇ이러러ㅎ게게 ㅆ써져져서서 이잏이햊해좀좀


    8년 전 link
  • ahn
    ahn

    아 드디어 풀렸네요. 감사합니다. 그런데
    f_swap -> for state var->i, i 는 무슨뜻인가요?
    참고로 한글로 쓰시려면 메모장에 쓰신 후 붙여넣기 하시면 돼요


    8년 전 link
  • pushbell7
    pushbell7

    포문 변수가 둘다 i길래요 ㅋㅋㅋ
    절묘하게 이상없이 돌아가서 놀랐네요


    8년 전 link
  • ahn
    ahn

    아 진짜 그러네요!
    정말 자세하게 봐주셔서 감사합니다 (__)ㅠㅠ!!!!!


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