[풀이 - Lisa's Workbook] : <Easy / 91.18%>
더보기
int workbook(int n, int k, vector<int> arr)
{
int result = 0;
//
int page = 1;
//
for(int i = 0; i < arr.size(); ++i)
{
int count = 1;
//
while(true)
{
// Check Special Number
if(count == page)
++result;
// End chapter
if(count >= arr[i])
break;
// Next Page
if(count % k == 0)
++page;
// Count number
count++;
}
// Next Page
++page;
}
//
return result;
}
[풀이 - Flatland Space Stations] : <Easy / 79.88%>
더보기
int getDistToNearestStation(int city, const vector<int> c)
{
int result = INT_MAX;
//
for(int i = 0; i < c.size(); ++i)
{
int d = abs(c[i] - city);
//
if(result > d)
result = d;
}
//
return result;
}
//
int flatlandSpaceStations(int n, vector<int> c)
{
int result = INT_MIN;
//
for(int i = 0; i < n; ++i)
{
int d = getDistToNearestStation(i, c);
//
if(result < d)
result = d;
}
//
return result;
}
[풀이 - Fair Rations] : <Easy / 90.04%>
더보기
int fairRations(vector<int> B)
{
int result = 0;
//
int count = B.size();
for(int i = 0; i < count; ++i)
{
bool isOdd = B[i] % 2 == 1;
if(isOdd)
{
if(i == count - 1)
return -1; // Print "NO" outside after Func
else
{
B[i]++;
B[i+1]++;
result += 2;
}
}
}
//
return result;
}
//
int main()
{
...
// add this to after fairRations()
if(result == -1)
fout << "NO" << "\n";
else
fout << result << "\n";
...
}
# 문제와 관계도 없고 쓸데없이 생소한 영어단어가 많음
1. ration : 분배
2. benevolent : 자비로운
3. subjects : 백성, 신하
4. loaves : 빵덩이들
5. dwindling : 줄어드는
# 심지어 반환값이 int인 함수에서 "NO"를 출력하라고
문제가 이상해서 main함수로 내려가서 출력부 수정
'Algorithm' 카테고리의 다른 글
Hackerrank - Happy Ladybugs, Strange Counter, The Grid Search, 3D Surface Area (0) | 2021.02.24 |
---|---|
Hackerrank - Cavity Map, Manasa and Stones (0) | 2021.02.23 |
HackerRank - The Time in Words, Chocolate Feast, Service Lane (0) | 2021.02.19 |
HackerRank - Beautiful Triplets, Minimum Distances, Halloween Sale (0) | 2021.02.19 |
HackerRank - Bigger is Greater, Modified Kaprekar Numbers (0) | 2021.02.17 |