GameChoi
Choi Programming
GameChoi
전체 방문자
오늘
어제
  • 분류 전체보기 (468)
    • C++ Algorithm & Study (184)
      • C++ & Algorithm Strategies (45)
      • Game Math & DirectX 11 (72)
      • Server + UE5 (29)
      • Lyra Clone Coding (37)
    • Create Game (284)
      • [Window API] Game Client & .. (55)
      • [DirectX] DirectX 2D & 3D (155)
      • [UE5] BLUEPRINT & C++ (74)
    • odds and ends (0)
      • English (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • job queue
  • c++
  • Direct3D
  • protobuf
  • client
  • Destination Move Packet
  • Player State
  • Algorithm Strategies
  • UE5
  • Other Character
  • Game Room
  • Direct11
  • server
  • core
  • Game Server
  • Network Worker
  • GAME Client
  • session
  • RPG Game
  • Player Move Packet

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
GameChoi

Choi Programming

[Programmers] 문자열 내 p와 y의 개수
C++ Algorithm & Study/C++ & Algorithm Strategies

[Programmers] 문자열 내 p와 y의 개수

2023. 2. 6. 23:57

https://school.programmers.co.kr/learn/courses/30/lessons/12916

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

0. Headers

#include <string>
using namespace std;

1. 알고리즘

 - s의 모든 값들을 가지고와서 p(P)와 y(Y)의 값을 찾은 후 변수의 값에 더해줌

#include <string>
using namespace std;

bool solution(string s)
{
    int p = 0;
    int y = 0;
    for (int i = 0; i < s.length(); i++) 
    {
        if (s[i] == 'p' || s[i] == 'P')  p++;
        else if (s[i] == 'y' || s[i] == 'Y') y++;
    }
    return (p == y);
}

2. 완성 코드

#include <string>
using namespace std;

bool solution(string s)
{
    int p = 0;
    int y = 0;
    for (int i = 0; i < s.length(); i++) 
    {
        if (s[i] == 'p' || s[i] == 'P')  p++;
        else if (s[i] == 'y' || s[i] == 'Y') y++;
    }
    return (p == y);
}

저작자표시 (새창열림)

'C++ Algorithm & Study > C++ & Algorithm Strategies' 카테고리의 다른 글

[Algorithm Strategies] 02. Exhaustive Search - Picnic  (0) 2023.07.11
[Algorithm Strategies] 01. Exhaustive Search - Boggle  (0) 2023.07.10
[Algorithm Strategies] 00. Contents  (0) 2023.02.05
[Programmers] JadenCase 문자열 만들기  (0) 2023.02.03
[Programmers] 크기가 작은 부분 문자열  (0) 2023.02.02
    'C++ Algorithm & Study/C++ & Algorithm Strategies' 카테고리의 다른 글
    • [Algorithm Strategies] 02. Exhaustive Search - Picnic
    • [Algorithm Strategies] 01. Exhaustive Search - Boggle
    • [Algorithm Strategies] 00. Contents
    • [Programmers] JadenCase 문자열 만들기
    GameChoi
    GameChoi

    티스토리툴바