ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 알고리즘 문제 복습(10~20번)
    인프런 알고리즘테스트 문제 2020. 9. 19. 15:30

    10번

    #include<iostream>
    #include<vector>
    using namespace std;
    int main() {
    	int n;
    	int cnt=0;
    	int temp;
    	cin >> n;
    	vector<int> arr(n);
    	for (int i = 1; i <= n; i++)
    	{
    		temp = i;
    		while (temp!=0)
    		{
    			temp = temp / 10;
    			cnt++;
    		}
    	}
    	cout << cnt;
    }

     

    11번(중요)

    #include<iostream>
    #include<vector>
    using namespace std;
    int main() {
    	int c = 1;
    	int d = 9;
    	int res = 0;
    	int sum = 0;
    	int n = 0;
    	cin >> n;
    	while (sum+d<n)
    	{
    		res = res + (c*d);
    		sum = sum + d;
    		c++;
    		d = d * 10;
    	}
    	res = res + ((n - sum)*c);
    	cout << res;
    }

     

    12번

    #include<iostream>
    #include<vector>
    using namespace std;
    
    int main()
    {
    	char number[9] = {'1','2','3','4','5','6','7','8','9'};
    	char arr[100];
    	int result[10] = {0};
    	int max=0;
    	int temp = 0;
    	cin >> arr;
    
    	for (int i=0; i < 100; i++)
    	{
    		for (int j = 0; j < 9; j++)
    		{
    			if (arr[i] == number[j])
    			{
    				result[j + 1]++;
    			}
    		}
    	}
    	for (int i = 1; i <= 9;i++)
    	{
    		if (result[i] > max)
    		{
    			max = result[i];
    			temp = i;
    		}
    		else if (result[i] == max)
    		{
    			if (temp < i)
    			{
    				temp = i;
    			}
    		}
    	}
    	cout << temp;
    
    }

    '인프런 알고리즘테스트 문제' 카테고리의 다른 글

    57번 재귀함수  (0) 2020.10.04
    56번 재귀함수  (0) 2020.10.04
    42번 이분검색 알고리즘  (0) 2020.09.18
    41번 알고리즘  (0) 2020.09.18
    알고리즘 문제 복습(1~10)  (0) 2020.09.18
Designed by Tistory.