Codeforces - 1676A-Lucky?

HoJeong Im·2022년 9월 3일
0

Codeforces

목록 보기
9/13

Problem

https://codeforces.com/problemset/problem/1676/A

Code

//
// Created by imhojeong on 2022-09-03.
//
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

int main() {

    int t;

    cin >> t;
    cin.ignore();

    for(int i = 0 ; i < t ; i++){

        string s1;
        cin >> s1;
        istringstream ssi(s1);
        string token;
        int len = s1.length();
        int sumLeft= 0 , sumRight = 0;
        char char_arr[len+1];
        strcpy(char_arr, s1.c_str());

        for(int j = 0 ; j < len/2 ; j++){
            sumLeft += (char_arr[j]) - '0';
            sumRight += (char_arr[(len/2)+j]) - '0';
//            cout << (char_arr[(len/2)+j]) << endl;
        }

//        cout << sumLeft << ", " << sumRight << endl;
        if(sumLeft == sumRight) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }

    }

}

Reference

  • 기초적인 수학 연산 문제입니다.

  • C++를 시작한지 얼마 안 되어, 꾸준히 연습하고자 올려보았습니다.

  • isstringstream, strcpy가 아직 쓰는 게 어색합니다 ㅠ

profile
꾸준함이 제일 빠른 길이었다

0개의 댓글