0428

민우이·2022년 4월 29일

@@@@ OX문제 문자열 @@@@
#include <stdio.h>

int main(void)
{
int T;
scanf("%d", &T);

while (T--)
{
// 입력 : OX 퀴즈의 결과를 입력받는다.
char oxResult[80] = "";
scanf("%79s", oxResult);

  // 처리 : 점수 계산
  // 1. O일 때 점수가 늘어남.
  // 2. 그 문제까지 연속된 O의 개수만큼 점수가 늘어남.

  // 2. 1번으로 돌아가 문자열의 끝을 만날 때까지 반복한다.
  int score = 0;
  int consecutiveCorrectAnswerCount = 0;
  for (int i = 0; oxResult[i] != '\0'; ++i)
  {
     // 1. 현재 문제를 맞췄는가?
     if (oxResult[i] == 'O')
     {
        // 1-1. 맞았다면 연속적으로 맞춘만큼 점수를 부여한다.
        ++consecutiveCorrectAnswerCount;
        score += consecutiveCorrectAnswerCount;
     }
     else
     {
        consecutiveCorrectAnswerCount = 0;
     }
  }
  
  // 출력 : 점수 출력
  printf("%d\n", score);

}

return 0;
}

@@@@EOF문제 @@@@
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

char word[1000001];

int main(void)
{
int count = 0;
while (1)
{
if (EOF == scanf("%s", word))
{
break;
}

  ++count;

}

printf("%d", count);

return 0;
}

@@@@ 알파벳 위치 @@@@
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
// 입력 : 단어를 입력받는다.
char S[101] = "";
scanf("%s", S);

// 처리 : 알파벳 위치를 찾는다.
int count[26];
for (int i = 0; i < 26; ++i)
{
count[i] = -1;
}

for (int i = 0; S[i] != '\0'; ++i)
{
int index = S[i] - 'a';

  if (count[index] == -1)

  {
     count[index] = i;
  }

}

// 출력 : 알파벳 위치를 출력한다.
for (int i = 0; i < 26; i++)
{
printf("%d ", count[i]);
}

return 0;
}

@@@@ 그룹단어 @@@@
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
int N;
scanf("%d", &N);

int count = 0; // 그룹 단어 개수를 저장할 객체
for (int i = 0; i < N; ++i)
{
// 단어 입력 받음
char word[101] = "";
scanf("%100s", word);

  // 그룹단어인지 확인
  // 그룹단어 : 같은 문자가 연속적으로 나오는 단어

  int isGroupWord = 1; // 그룹단어인지 확인하기 위한 객체
  int isAlreadyExist[26] = { 0 }; // 이전에 해당 문자가 나왔는지 저장하기 위한 객체
  // 
  char prevCharacter = '\0'; // 문자가 연속적으로 잘 나오고 있는지 저장하기 위한 객체
  for (int i = 0; word[i] != '\0'; ++i)
  {
     if (prevCharacter != word[i])
     {
        int alphabet = word[i] - 'a';

        if (isAlreadyExist[alphabet])
        {
           isGroupWord = 0;

           break;
        }

        isAlreadyExist[alphabet] = 1;
     }

     prevCharacter = word[i];
  }

  // 그룹 단어라면 센다.
  if (isGroupWord)
  {
     ++count;
  }

}

printf("%d", count);

return 0;
}

0개의 댓글