티스토리 뷰

사진

11월 3째주 첫 코드리뷰

U_황상진 2016. 11. 18. 16:07




11월 3째주 첫 코드리뷰

타일수 구하기


코드 예시

#include< stdio.h >
 
 
int main()
{
    int a, b,arest,brest, wtile,ptile;
    scanf("%d", &a);
    scanf("%d", &b);
    arest = a % 8;
    brest = b % 8;
 
    a /= 8;
    b /= 8;
    wtile = a*b;
    if (arest != 0)
    {
        if (brest == 0)
        {
            ptile = b;
        }
        else
        {
            ptile = a + b +1 ;
        }
    }
    else
    {
        if (brest == 0)
        {
            ptile = 0;
        }
        else
        {
            ptile = a;
        }
    }
 
    printf("The number of whole tiles is %d part tiles is %d", wtile,ptile);
 
 
    return 0;
}



두번째 문제

캥거루




코드 예시


#include< iostream >
using namespace std;
 
int main(){
     
    int a, b, c;
    cin >> a >> b >> c;
    int cha1, cha2;
 
    cha1 = b - a;
    cha2 = c - b;
 
    if (cha1 > cha2){
        cout << cha1 - 1;
    }
    else{
        cout << cha2 - 1;
    }
 
    return 0;
 
}








댓글
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크