Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- directx
- 라인트레이서
- Visual Micro
- queue
- 아두이노 컴파일러
- 아두이노 소스
- set
- C언어
- stl
- map
- c++
- WinAPI
- Algorithm
- Array
- arduino compiler
- html
- 통계학
- 시스템프로그래밍
- Deque
- 운영체제
- Arduino
- list
- 컴퓨터 그래픽스
- priority_queue
- vector
- LineTracer
- 자료구조
- 수광 소자
- 아두이노
- Stack
Archives
- Today
- Total
Kim's Programming
1285. 아름이의 돌 던지기 본문
1285. 아름이의 돌 던지기
풀이 방법
처음엔 절대값이 가장 작은 값을 찾은 다음 그 값의 개수를 세어 답을 구했다 하지만 전체를 다시 훑어 보는 것 보단 배열 하나를 두어 저장을 하고 인덱스를 증가 시키면서 가장 먼져 만나는 0이 아닌 값을 찾는 것이 나은거 같다.
<코드>
첫 번째
#include<iostream> #include <cmath> int main() { int n{ 0 }; std::cin >> n; for (int testCase = 1; testCase <= n; testCase++) { int peopleCount; std::cin>>peopleCount; int* dataArray = new int[peopleCount]; int min{100000}; for(int i=0;i<peopleCount ;i++) { std::cin>>dataArray[i]; if(abs(dataArray[i]) <min) min = abs(dataArray[i]); } int answer{0}; for(int i=0;i<peopleCount ;i++) if(abs(dataArray[i]) ==min) answer++; std::cout << "#" << testCase << ' ' << min<<" "<<answer << "\n"; delete[] dataArray; } return 0; }
두 번쨰
#include <iostream> #include <cmath> #include <cstring> int main() { int n{ 0 }; std::cin >> n; for (int testCase = 1; testCase <= n; testCase++) { int peopleCount; std::cin >> peopleCount; int dataArray[100000 + 1]; memset(dataArray, 0, sizeof(dataArray)); for (int i = 0; i < peopleCount; i++) { int input; std::cin >> input; dataArray[abs(input)]++; } int answer = 0, min = 0; for (int i = 0; i < 100000 + 1; i++) { if (dataArray[i] != 0) { answer = dataArray[i]; min = i; break; } } std::cout << "#" << testCase << ' ' << min << " " << answer << "\n"; } return 0; }
'SW ExpertAcademy > D2' 카테고리의 다른 글
1940. 가랏! RC카! (0) | 2018.12.01 |
---|---|
1928. Base64 Decoder (0) | 2018.12.01 |
1288. 새로운 불면증 치료법 (0) | 2018.12.01 |
1284. 수도 요금 경쟁 (0) | 2018.11.30 |
1204. [S/W 문제해결 기본] 1일차 - 최빈수 구하기 (0) | 2018.11.30 |