황찌옹
정리왕옹옹
황찌옹
GitHub Contribution
Loading data ...
  • 분류 전체보기 (158)
    • [ 알고리즘 ] (96)
      • Implementation (24)
      • Brute Force (6)
      • String (4)
      • Greedy (14)
      • DFS, BFS (13)
      • Back Tracking (4)
      • Sort & Binary Search (6)
      • DP (8)
      • Shortest Path (5)
      • Hash (3)
      • Stack, Queue (4)
      • Heap (1)
      • Tree (1)
      • Mathematics (1)
      • Ad-Hoc (1)
      • 기타 (COS Pro, etc) (1)
    • [ 언어 및 문법 ] (23)
      • Python (5)
      • C, C++ (13)
      • SQL (1)
      • 공통 개념(CS) (4)
    • [ Error ] (21)
      • Radiomics Feature Extraction (6)
      • CT Skin Segmentation (12)
      • etc (3)
    • [ Git ] (7)
    • [ 환경 설정 및 기타] (6)
    • [ 공부 ] (2)
      • AI, ML (0)
      • Computer Vision (0)
      • Image Processing (1)
      • QT (0)
      • AWS (1)
      • 의료 (0)
    • [ 포트폴리오 ] (1)
      • 🙋‍♀️자기 소개🙋‍♀️ (1)
      • 프로젝트 (0)
      • 공모전 (0)
      • 자격증 (0)
      • 대내외활동 (0)
      • 논문 (0)
      • 교육 봉사 (0)
    • [ 취준 ] (2)
      • 채용 설명회, 직무 상담 (1)
      • 취준 후기 (1)

블로그 메뉴

  • ❤️깃허브❤️

인기 글

태그

  • keras
  • git
  • config
  • QT
  • 씹어먹는C++
  • SQL
  • configuration
  • Python
  • Anaconda
  • c++
  • aws
  • Visual Studio
  • pyplot
  • Cloud
  • cos pro
  • cs
  • tensorflow
  • numpy
  • OpenCV
  • 모두의코드

최근 댓글

최근 글

전체 방문자
오늘
어제
hELLO · Designed By 정상우.
황찌옹

정리왕옹옹

[ 알고리즘 ]/Implementation

[백준] 14954. Happy Number

2022. 6. 29. 03:29

 

📌문제

https://www.acmicpc.net/problem/14954

 

🎖️난이도

 

✔️풀이

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <math.h>
#include <tuple>

using namespace std;

int n, i;
bool visited[730]; // false

int main() {
    cin >> n;

    // 메모리 초과 해결을 위해 [730] 넘는 숫자들 먼저 1회 처리
    int first_sum = 0;
    int first_ii = n;
    while (first_ii != 0) {
        first_sum += pow(first_ii % 10, 2);
        first_ii /= 10;
    }
    i = first_sum;

    while (1) {
        if (visited[i]) {
            cout << "UNHAPPY" << endl;
            break;
        }
        else if (i == 1) {
            cout << "HAPPY" << endl;
            break;
        }

        visited[i] = true;

        int pow_sum = 0;
        int ii = i;
        while (ii != 0) {
            pow_sum += pow(ii % 10, 2);
            ii /= 10;
        }
        i = pow_sum;
    }
    
    
    return 0;
}

'[ 알고리즘 ] > Implementation' 카테고리의 다른 글

[백준] 2438. 별 찍기 - 1  (0) 2022.06.30
[CodeUp] 6098. 성실한 개미  (0) 2022.06.29
[CodeUp] 6096. 바둑알 십자 뒤집기  (0) 2022.06.29
[백준] 9455. 박스  (0) 2022.06.29
[백준] 13567. 로봇  (0) 2022.06.29
    황찌옹
    황찌옹
    다 정리해버리꺼야

    티스토리툴바