본문 바로가기

C++

백준 C++ 11654,13597,13752,14038,14681,14918,15000,15372,15439,15680,15700,15733,15802,15962,15963,16170,

#11654

#include <iostream>

using namespace std;

int main(){

    char c;
    cin >> c;

    int a = int(c);
    cout << a;

}

#13597

#include <iostream>

using namespace std;

int main(){

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

    if ((a>=1 && a<= 13)&&(b>=1 && b<=13)){

        if(a>=b){
            cout << a;
        }

        else {
            cout << b;
        }
    }

    return 0;

}

#13572

#include <iostream>

using namespace std;

int main(){

    int n,k;
    cin >> n;

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

        cin >> k;
        for (int i=0;i<k;i++){
            cout<<"=";
        }
        cout << endl;

    }

    return 0;

}

#14038

#include <iostream>

using namespace std;

int main(){

    char list[6];
    int cnt = 0;

    for (int i=0; i<6; i++){
        cin >> list[i];
    }

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

        if (list[i] == 'W'){
            cnt++;
        }
    }

    if (1<=cnt && cnt<=2){
        cout << 3;
    }

    else if (3<=cnt && cnt<=4){
        cout<<2;
    }
    else if (5<=cnt && cnt<=6){
        cout <<1;
    }
    else {
        cout << -1;
    }

    return 0;

}

#14681

#include <iostream>

using namespace std;

int main(){

    int x,y;
    cin >> x;
    cin >> y;

    if(x>0 && y>0){
        cout << 1;
    }
    else if(x<0 && y>0){
        cout <<2;
    }
    else if(x<0 && y<0){
        cout <<3;
    }
    else if(x>0 && y<0){
        cout<<4;
    }
    else {
        cout<<" ";
    }

    return 0;

}

#14918

#include <iostream>

using namespace std;

int main(){

    int a,b;
    cin >> a >> b;
    cout << a+b <<endl;

    return 0;

}

#15000

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

int main() {

    //소문자->대문자는 -=32해주면 된다.
    string c;
    cin >> c;

    for (int i=0;i<c.size();i++){
        c[i] -= 32;
    }

    cout <<c;
    return 0;

}

#15372

#include <iostream>

using namespace std;

int main() {

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

    int t;
    long long n;
    cin >> t;

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

        cin >> n;
        long long k = n*n;

        cout << k << '\n';
    }
    return 0;
}

이 문제 같은 경우는 long long을 써주는 것과, cin과 cout의 속도를 빠르게 해줄 

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

이 두 개를 입력해야 틀렸습니다,시간초과와 같은 문구들이 뜨지 않는 것을 볼 수 있다.

#15439

#include <iostream>

using namespace std;

int main() {

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

    int n;
    cin >> n;
    cout << n*(n-1);
    return 0;
}

#15680

#include <iostream>

using namespace std;

int main() {

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

    int n;
    cin >> n;

    if(n==1){
        cout<<"Leading the Way to the Future";
    }
    else if (n==0){
        cout<<"YONSEI";
    }

    return 0;

}

#15700

#include <iostream>

using namespace std;

int main() {

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

    long long n,m;
    cin >> n >> m;
    long long sum = n*m,cnt =0;

    cout<<sum/2;

}

#15733

#include <iostream>

using namespace std;

int main() {

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

    cout<<"I'm Sexy";
    return 0;

}

#15802

#include <iostream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cout<<1;
    
    return 0;

}

#15962

#include <iostream>

using namespace std;

int main() {

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

    cout<<"파이팅!!";

    return 0;

}

#15963

#include <iostream>

using namespace std;

int main() {

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

    long long n,m;
    cin >> n >> m;

    if(n==m){
        cout<<1;
    }
    else {
        cout<<0;
    }

    return 0;

}

#16170

#include <iostream>
#include <ctime>

using namespace std;

int main() {

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

    time_t timer = time(NULL);
    struct tm* t = localtime(&timer);

    struct tm {
        int tm_mday;        // 일, range 1 to 31
        int tm_mon;         // 월, range 0 to 11
        int tm_year;        // 1900년 부터의 년
    };

    cout << t->tm_year+1900 <<'\n';
    cout << t->tm_mon+1<<'\n';
    cout << t->tm_mday;

    return 0;


}

이 문제는 좀 어려웠다 나는 시간 함수 문제에 약한 것 같다. time함수에 대해 더욱 공부해야겠다. 구조체와 포인터에 대해 공부를 더 해야할 것 같다.