강의

멘토링

커뮤니티

Inflearn Community Q&A

yeongjuning1121's profile image
yeongjuning1121

asked

Introduction to Algorithm Problem Solving for IT Employment (with C/C++): Coding Test Preparation

21. Card game (basic coding design)

강사님하고 별반 다를거 ㅇ벗는 코드인데 타임리미트가 걸립니다.

Written on

·

228

0

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

using namespace std;

int main()

{

int rou = 10;

int A[10] = {}, B[10] = {};

int scoA = 0, scoB = 0, lastW = 0;

for (int i = 0; i < rou; i++)

scanf("%d ", &A[i]);

for (int i = 0; i < rou; i++)

scanf("%d ", &B[i]);

for (int i = 0; i < rou; i++)

{

if (A[i] == B[i])

{

scoA += 1;

scoB += 1;

}

else if (A[i] > B[i])

{

scoA += 3;

lastW = 1;

}

else

{

scoB += 3;

lastW = 2;

}

}

printf("%d %d\n", scoA, scoB);

if (scoA > scoB)

printf("A");

else if (scoA < scoB)

printf("B");

else if (scoA == scoB)

{

if (lastW == 0)

printf("D");

else if (lastW == 1)

printf("A");

else if (lastW == 2)

printf("B");

}

return 0;

}

저 위의 코드가 타임리미트가 걸리는데 강사님과 크게 다르지않는 코드에서 타임리미트가 걸려서요..; 제가 뭔가 잘못된건가요? 답은 제대로 나옵니다.

C++코테 준비 같이 해요!

Answer 2

0

yeongjuning1121님의 프로필 이미지
yeongjuning1121
Questioner

아 저기에 띄어쓰기를 안하니깐 제대로 테스트가 되네요 감사합니다!

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^ 

scanf로 읽을 때 마지막에 읽는 scanf에서는 %d뒤를 뛰어쓰기 하면 안됩니다. scanf("%d", &B[i])와 같이 하면 됩니다.

yeongjuning1121's profile image
yeongjuning1121

asked

Ask a question