반응형

4673번 문제 : 셀프 넘버

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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
 
using namespace std;
 
bool numArr[10001];
 
void SelfNumberCheck(int num)
{
    int sum = num;
    int temp = num;
 
    while (temp > 0)
    {
        sum += temp % 10;
        temp /= 10;
    }
 
    if (sum > 10000 || numArr[sum] == false)
        return;
 
    numArr[sum] = false;
    SelfNumberCheck(sum);
}
 
int main()
{
    for (int i = 1; i <= 10000; i++//initialize
    {
        numArr[i] = true;
    }
 
    for (int i = 1; i <= 10000; i++)
    {
        SelfNumberCheck(i);
    }
 
    for (int i = 1; i <= 10000; i++)
    {
        if (numArr[i] == true)
            cout << i << endl;
    }
 
    return 0;
}
cs


1065번 문제 : 한수

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <vector>
using namespace std;
bool CheckIfHansoo(int n)
{
   if (n < 100)
   {
      return true;
   }
   vector<int> v;
   while (n > 0)
   {
      int num = n % 10;
      v.push_back(num);
      n /= 10;
   }
   
   int diff = v.at(0- v.at(1);
   for (int i = 0; i < v.size() - 1; i++)
   {
      int temp = v.at(i) - v.at(i + 1);
      if (diff != temp)
         return false;
   }
   return true;
}
int main()
{
   int inp;
   cin >> inp;
   int num = 0;
   for (int i = 1; i <= inp; i++)
   {
      if (CheckIfHansoo(i))
         num++;
   }
   cout << num;
   return 0;
}
cs


반응형

'C++ Algorithm > 백준 알고리즘 문제 풀이' 카테고리의 다른 글

문자열 사용하기  (0) 2018.11.27
1차원 배열 사용하기  (0) 2018.11.27
if문 사용해보기  (0) 2018.11.14
for문 사용해보기  (0) 2018.11.07
사칙연산 도전하기  (0) 2018.11.07
반응형

학교에서 진행하는 SW Festival에 참가했다

비전공생으로서 느낌을 적자면 전체적으로 상당히 아쉬웠고 그들(컴공생)만의 리그였다...

또 게임 SW 작품들도 은근히 많았는데 게임 SW에는 아무도 크게 관심이 없었다...

(게임작품의 경우 퀄리티가 떨어지는 작품이 많아서 그런게 아닌가 싶기도 하다)


전시한 작품들은 교수들에 의해 평가 받기도 하는데

교수들은 새로운 창업 아이템으로서의 SW 작품만 찾는것 같았다... 

그래서 더 아쉬웠다 (한분빼고 제대로된 평가도 못받았고, 내가 전시한 작품이 게임이라는 이유로 그냥 지나친 경우가 대부분이다)


나름 게임을 SW의 꽃으로 생각하고 있었던 나로서 게임이 찬밥 신세 당하니까 솔직히 너무 아쉬웠다...

(구체적인 구현 결과물은 없고 그럴사한 사업 아이템 제시하는식의 작품들이 더 인기가 많았다...)


뭔가 게임제작이 관심이 있는 사람들끼리 모여서 얘기라도 하고 싶었는데 

게임 전시자들은 다들 사라지고 없고... (찬밥신세여서 그런가?)

그냥 3~4시간동안 그냥 서있었다.

아무튼 좋은 경험이라고 생각하기엔 아쉬움이 너무 많이 남는 경험이었다...


앞으로 국제캠퍼스까지가서 뻘짓하는 일은 없을것 같다.


아쉬우니까 여기라도 포스터 올려야겠다...ㅠ











반응형
반응형

9498번 문제 : 시험 성적

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
 
using namespace std;
 
int main()
{
    int score;
    cin >> score;
 
    if(score<=100 && score>=90)
        cout<<"A"<<endl;
    else if((score<90 && score>=80))
        cout<<"B"<<endl;
    else if((score<80 && score>=70))
        cout<<"C"<<endl;
    else if((score<70 && score>=60))
        cout<<"D"<<endl;
    else
        cout<<"F"<<endl;
 
 
    return 0;
}
cs



10817번 문제 : 세 수

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
 
    vector<int> v;
 
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
 
    sort(v.begin(), v.end());
 
    cout<< v.at(1)<<endl;
 
    return 0;
}
cs


메모:

-STL 사용하지 않고 단순 비교연산자로 풀수 있음: 세수이기때문에 속도면에서 더 빠를수도?


10871번 문제 : X보다 작은 수

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int a,b;
    cin>>a>>b;
 
    vector<int> v;
 
    while(a>0)
    {
        int num;
        cin>>num;
        if(num<b)
            v.push_back(num);
        a--;
    }
 
    for(int i=0; i<v.size(); ++i)
    {
        cout<<v.at(i)<<" ";
    }
    
    return 0;
}
cs


메모:

-vector안에 값모두 출력할떄 auto 키워드사용해서 출력가능

1
2
3
4
for(auto i: v)
{
    cout<<i<<" ";
}
cs


1546번 문제 : 평균

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int a;
    cin>>a;
 
    vector<float> v;
 
    while(a>0)
    {
        float num;
        cin>>num;
        v.push_back(num);
        a--;
    }
    sort(v.begin(), v.end());
 
    for(int i=0; i<v.size(); i++)
    {
        v.at(i) = v.at(i) / v.at(v.size()-1* 100;
    }
 
    float sum = 0;
    
    for(int i=0; i<v.size(); i++)
    {
        sum += v.at(i);
    }
 
    float mean = sum / v.size();
    
    cout<< mean <<endl;
 
    return 0;
}
cs


4344번 문제 : 평균은 넘겠지 

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
float GetMean(vector<float> v)
{
    float sum = 0;
    for (int i = 0; i<v.size(); i++)
        sum += v.at(i);
 
    float mean = sum / v.size();
    return mean;
}
 
 
int main()
{
    int a;
    cin >> a;
 
    vector<float> answer;
 
    while (a>0)
    {
        int b;
        cin >> b;
        vector<float> v;
        v.clear();
        while (b>0)
        {
            float num;
            cin >> num;
            v.push_back(num);
            b--;
        }
 
        int num = 0;
        float mean = GetMean(v);
        for (int i = 0; i<v.size(); i++)
        {
            if (v.at(i)> mean)
                num++;
        }
 
        answer.push_back((float)num / v.size() * 100);
 
        a--;
    }
 
    cout.setf(ios::fixed);
    cout.precision(3);
 
    for (int i = 0; i<answer.size(); i++)
    {
        float result = round(answer.at(i)*1000/ 1000;
        cout << result << "%" << endl;
    }
 
    return 0;
}
cs

메모:
-소수점 지정
1
2
    cout.setf(ios::fixed);
    cout.precision(3);
cs

-반올림의 경우는 <math.h>의 round()함수를 사용하여 구할 수 있음




1110번 문제 : 더하기 사이클

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
 
using namespace std;
 
int main()
{
    int initialNum;
    int counter = 0;
    cin >> initialNum;
 
    if (initialNum < 10)
    {
        initialNum = initialNum * 10;    
    }
 
    int temp = initialNum;
    int newNum1 = 0;
    int newNum2 = 0;
    int finalnum = 0;
 
    while (initialNum != finalnum )
    {
        newNum1 = temp / 10 + temp % 10;
        newNum1 = newNum1 % 10;
        newNum2 = temp % 10;
        finalnum = newNum2 * 10 + newNum1;
        temp = finalnum;
        counter++;
    }
 
    if (initialNum == 0)
        counter = 1;
 
    cout << counter << endl;
 
    return 0;
}
cs


메모:

- input값이 0일때 주의!

반응형

'C++ Algorithm > 백준 알고리즘 문제 풀이' 카테고리의 다른 글

1차원 배열 사용하기  (0) 2018.11.27
함수 사용하기  (0) 2018.11.18
for문 사용해보기  (0) 2018.11.07
사칙연산 도전하기  (0) 2018.11.07
입/출력 받아보기  (0) 2018.11.06
반응형

2741번 문제 : N찍기

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int i = 1; i <= num; i++)
    {
        cout << i;
        if (i < num)
            cout << "\n";
    }
 
    return 0;
}
cs


메모:

-"\n" 대신 endl 사용하면 시간초과발생 (속도 \n(더 빠름)> endl)

-만약 더 속도 빠르게 하려면 cout 대신 <cstdio>의 printf함수가 더빠름



2742번 문제 : 기찍 N

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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int i = num; i >= 1; i--)
    {
        cout << i;
        if (i > 1)
            cout << "\n";
    }
 
    return 0;
}
cs



2739번 문제 : 구구단

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int i = 1; i < 10; i++)
    {
        cout << num << " * " << i << " = " << num * i;
        if (i < 9)
            cout << "\n";
    }
 
    return 0;
}
cs


2438번 문제 : 별 찍기 - 1

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int row = 0; row < num; row++)
    {
        for (int i = 0; i < row + 1; i++)
            cout << "*";
        if(row < num-1)
            cout << "\n";
    }
 
    return 0;
}
cs


2439번 문제 : 별 찍기 - 2

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int row = 0; row < num; row++)
    {
        for (int i = 0; i < num-row-1; i++)
            cout << " ";
 
        for (int i = 0; i < row + 1; i++)
            cout << "*";
 
        if(row < num-1)
            cout << "\n";
    }
 
    return 0;
}
cs


메모:

-푸는 방법은 아주 다양할듯...


2440번 문제 : 별 찍기 - 3

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int row = 0; row < num; row++)
    {
        for (int i = 0; i < num-row; i++)
            cout << "*";
 
        if(row < num-1)
            cout << "\n";
    }
 
    return 0;
}
cs


2441번 문제 : 별 찍기 - 4

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
 
int main(void) {
    int num;
    cin >> num;
 
    for (int row = 0; row < num; row++)
    {
        for (int i = 0; i < row; i++)
            cout << " ";
 
        for (int i = 0; i < num-row; i++)
            cout << "*";
 
        if(row < num-1)
            cout << "\n";
    }
 
    return 0;
}
cs


1924번 문제 : 2007년

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;
 
int main(void) {
 
    string dayName[7= { "SUN" , "MON""TUE""WED""THU""FRI""SAT" };
    int month[13= { 0312831303130313130313031 };
    int totalDays = 0;
    int inputM, inputD;
 
    cin >> inputM >> inputD;
 
    for (int i = 0; i < inputM; i++)
        totalDays += month[i];
    totalDays += inputD;
    int leftover = totalDays % 7;
 
    cout << dayName[leftover];
 
    return 0;
}
cs


8393번 문제 : 합

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
 
int main(void) {
 
    int input;
    int sum = 0;
    cin >> input;
 
    for (int i = 1; i <= input; i++)
    {
        sum += i;
    }
    
    cout << sum;
 
    return 0;
}
cs


11720번 문제 : 숫자의 합

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;
 
int main(void) {
 
    int sum = 0;
 
    int inputA;
    string inputB;
 
    cin >> inputA >> inputB;
 
    for (int i = 0; i < inputA; i++)
    {
        sum += inputB[i] - 48//Subtract 48 because of ASCII Code
    }
    
    cout << sum;
 
    return 0;
}
cs


메모:

-string의 각각 원소는 Char값인 동시에 int값을 가지고 있음. ASCII Code에 의해 0은 48부터 시작

-ASCII Code Table은 아래와 같음


Ascii Table


11721번 문제 : 열 개씩 끊어 출력하기

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string line;
    cin >> line;
 
    for (int i = 0; i < line.size(); i++)
    {
        cout << line[i];
 
        if (i !=0 && i % 10 == 9)
            cout << endl;
    }
 
    return 0;
}
cs



15552번 문제 : 빠른 A+B

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cstdio>
using namespace std;
 
int main() {
    
    int num;
    scanf("%d"&num);
 
    while (num > 0)
    {
        int a, b;
        scanf("%d %d"&a, &b);
        printf("%d\n", a + b);
 
        num--;
    }
 
    return 0;
}
cs


메모: 

-cin과 cout보다 빠른 c언어 계열 함수인 scanf, printf 사용

-비쥬얼스튜디오는 scanf / printf 사용하면 컴파일 에러 발생, scanf_s / printf_s 사용해야함

-cin cout를 사용하고 싶으면 

1
2
3
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
cs
이런 방법이 있다고함... (하지만 C언어 계열 함수를 사용하는게 좋다고함)


반응형

'C++ Algorithm > 백준 알고리즘 문제 풀이' 카테고리의 다른 글

1차원 배열 사용하기  (0) 2018.11.27
함수 사용하기  (0) 2018.11.18
if문 사용해보기  (0) 2018.11.14
사칙연산 도전하기  (0) 2018.11.07
입/출력 받아보기  (0) 2018.11.06
반응형

10530번 문제 : 나머지


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
 
int main() {
 
    int a, b;
    cin >> a >> b;
 
    double result = (double)a / (double)b;
 
    cout << fixed;
    cout.precision(9);
    cout << result << endl;
 
    return 0;
}
 
cs


10869번 문제 : 사칙연산

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


1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
 
int main(void) {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl << a - b << endl << a * b << endl << a / b << endl << a % b;
    return 0;
}
cs


10530번 문제 : 나머지


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
 
int main() {
    
    int x, y, z;
    cin >> x >> y >> z;
    
    cout << (x + y) % z << endl;
    cout << (x % z + y % z) % z << endl;
    cout << (x * y) % z << endl;
    cout << ((x % z) * (y % z)) % z << endl;
 
    return 0;
}
cs


2389번 문제: 설탕 배달

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;
 
int main(void) {
    int threeKgNum, fiveKgNum, leastNum;
    bool isChanged = false;
    int input;
 
    cin >> input;
    
    fiveKgNum = input / 5;
    leastNum = input;
 
    while (fiveKgNum >= 0
    {
        int leftover = input - fiveKgNum * 5;
        if (leftover % 3 == 0)
        {
            threeKgNum = leftover / 3;
 
            int totalNum = fiveKgNum + threeKgNum;
            if (totalNum <= leastNum)
            {
                isChanged = true;
                leastNum = totalNum;
            }
        }
        fiveKgNum--;
 
        if (fiveKgNum < 0 && isChanged == false)
        {
            leastNum = -1;
        }
    }
 
    cout << leastNum << endl;
    
    return 0;
}
cs


반응형

'C++ Algorithm > 백준 알고리즘 문제 풀이' 카테고리의 다른 글

1차원 배열 사용하기  (0) 2018.11.27
함수 사용하기  (0) 2018.11.18
if문 사용해보기  (0) 2018.11.14
for문 사용해보기  (0) 2018.11.07
입/출력 받아보기  (0) 2018.11.06
반응형

입/출력 받아보기 문제는 기초문제가 많기 때문에 여러문제 묶어서 풀음



2557번 문제 Hello World!

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


1
2
3
4
5
6
7
#include <iostream>
using namespace std;
 
int main() {
    cout << "Hello World!" << endl;
    return 0;
}
cs


메모: 

-iostream의 cout 말고 <cstdio>의 printf도 사용가능 

-(속도상으론 printf가 더 빠르나 safety와 error, 확장성과 상속을 생각했을때 cout를 사용하는게 C++다움)



1000번 문제 : A+B

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


1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
 
int main() {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}
cs


1001번 문제 : A-B

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


1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
 
int main() {
    int a, b;
    cin >> a >> b;
    cout << a - b << endl;
    return 0;
}
cs


10172번 문제 : 개

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


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
 
int main() {
    cout << "|\\_/|" << endl;
    cout << "|q p|   /}" << endl;
    cout << "( 0 )\"\"\"\\" << endl;
    cout << "|\"^\"`    |" << endl;
    cout << "||_/=\\\\__|" << endl;
    return 0;
}
cs


메모:

-" " 문자열안에 큰따움표(") 표시는 \"로

-" " 문자열안에 역슬래시(\) 표시는 \\

-endl 대신 \n로 줄바꿈이가능 (\n이 속도상 더 빠름)


10718번 문제 : We Love Krri

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


1
2
3
4
5
6
7
#include <iostream>
using namespace std;
 
int main() {
    cout << "강한친구 대한육군" << endl << "강한친구 대한육군" << endl;
    return 0;
}
cs


메모:

-endl 대신 \n로 해도 될듯


11718번 문제 : 그대로 출력하기

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

11719번 문제 : 그대로 출력하기2

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


두 문제 정답 동일


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string line;
    while (getline(cin, line))
    {
        cout << line << endl;
    }
    return 0;
}
cs


반응형

'C++ Algorithm > 백준 알고리즘 문제 풀이' 카테고리의 다른 글

1차원 배열 사용하기  (0) 2018.11.27
함수 사용하기  (0) 2018.11.18
if문 사용해보기  (0) 2018.11.14
for문 사용해보기  (0) 2018.11.07
사칙연산 도전하기  (0) 2018.11.07

+ Recent posts