본문 바로가기

C++

백준 C++ 16394,16430,17009,17010,17094,17388,17530,17863,17869,18108,18398,19532,19602,20254,20332,20492,20499,21300,21591

#16394

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    cout << n-1946;

    return 0;

}

#16430

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b;
    cin >> a >> b;

    cout << b-a << '\n' << b;
    return 0;

}

#17009

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int apples=0, bannas=0;
    int n;

    for(int i=3;i>0;i--){

        cin >> n;
        apples += n*i;

    }

    for(int i=3;i>0;i--){
        cin >> n;
        bannas += n*i;
    }

    if(apples>bannas){
        cout<<"A";
    }
    else if(bannas>apples){
        cout<<"B";
    }
    else{
        cout<<"T";
    }

    return 0;

}

#17010

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int l,a;
    char b;
    cin >> l;

    for (int i=0;i<l;i++){
        cin >> a >> b;

        for (int i=0;i<a;i++){
            cout<<b;
        }
        cout << "\n";

    }

    return 0;

}

#17094

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int l;
    cin >> l;
    string s;
    int cnt_2=0 , cnt_e=0;

    cin >> s;

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

        if(s[i]=='2'){
            cnt_2++;
        }
        else if(s[i]=='e'){
            cnt_e++;
        }
    }

    if(cnt_2>cnt_e){
        cout << "2";
    }
    else if(cnt_2<cnt_e){
        cout << "e";
    }
    else {
        cout << "yee";
    }

    return 0;

}

#17388

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int s,k,h;
    cin >> s >> k >> h;
    int sum = s+k+h;

    if(sum >= 100){
        cout << "OK";
    }
    else {

        if(s<k && s<h){
            cout << "Soongsil";
        }
        else if(k<s && k<h){
            cout << "Korea";
        }
        else {
            cout <<"Hanyang";
        }

    }

    return 0;

}

#17530

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    int n[t];

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

        cin >> n[i];

    }

    int max = n[0];
    bool s = 0;

    for (int i=1;i<t;i++){
        if(n[i]>max){
            s = 1;
        }
    }

    if (s==1){
        cout<<"N";
    }
    else{
        cout<<"S";
    }

    return 0;

}

#17863

#include <iostream>
#include <string>
using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;

    //substr() string에 포함된 함수로 문자열의 일부를 리턴한다.
    //substr(0,2)로 하면 NO가 떠서 정답이 아니다.
    if(s.substr(0,3) == "555"){

        cout<<"YES";

    }
    else{
        cout<<"NO";
    }

    return 0;

}

#17869

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    long long n;
    cin >> n;
    int cnt = 0;

    while(n!=1){
        if(n%2 == 0){
            n /=2;
        }
        else {
            n +=1;
        }
        cnt ++;
    }

    cout << cnt;

    return 0 ;

}

int n; => 시간초과 발생 

long long n; 사용해야 시간 초과가 나지 않는다.

#18108

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int year;
    cin >> year;

    cout << year-543;

    return 0 ;

}

#18398

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t,n,a,b;
    cin >> t;

    for(int i=0;i<t;i++){
        cin >> n;
        for(int j=0;j<n;j++){
            cin >> a >> b;
            cout << a+b << " " << a*b<<'\n';
        }
    }

    return 0 ;

}

#19532

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    int x = (c*e-b*f) / (a*e-b*d);
    int y = (d*c-a*f) / (d*b-a*e);

    cout<<x<<" "<<y;

    return 0 ;

}

#19602

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int s,m,l;
    cin >> s;
    cin >> m;
    cin >> l;

    int sum = 1*s + 2*m + 3*l;
    if (sum>=10){
        cout<<"happy";
    }
    else{
        cout<<"sad";
    }

    return 0 ;

}

#20254

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int ur,tr,u0,t0;
    cin >> ur >> tr >> u0 >> t0;

    int sum = 56*ur + 24*tr + 14*u0 + 6*t0;
    cout << sum;

    return 0 ;

}

#20332

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n,w,sum =0;
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> w;
        sum += w;
    }

    if(sum%3 ==0){
        cout<<"yes";
    }
    else{
        cout<<"no";
    }

    return 0;

}

#20492

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    cout << (int)(n*0.78)<<" " << (int)((n*0.8)+((n*0.2)*0.78));

    return 0;

}

int형으로 형변환을 안 해서 출력이 지수로 되어서 틀렸다고 나왔다. 반드시 형변환을 하길 바란다.

#20499

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int k,d,a;
    char slash;
    cin >> k >> slash >> d >> slash >> a;

    if(k+a<d || d==0){
        cout<<"hasu";
    }
    else{
        cout<<"gosu";
    }

    return 0;

}

#21300

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    cout << a*5 + b*5 + c*5 + d*5 + e*5 + f*5;

    return 0;

}

#21591

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int wc,hc,ws,hs;
    cin >> wc >> hc >> ws >> hs;

    if((wc-ws)>1 && (hc-hs)>1){
        cout << true;
    }
    else{
        cout << false;
    }

    return 0;

}