[풀이 - Append and Delete]
더보기
string appendAndDelete(string s, string t, int k)
{
int lengthA = s.size();
int lengthB = t.size();
//
if(lengthA + lengthB < k)
return "Yes";
//
int count = 0;
int i = 0;
for(; s[i] == t[i] ; ++i) {}
//
count = (lengthA - i) + (lengthB - i);
//
if ((k - count) >= 0 && ((k - count) % 2) == 0)
return "Yes";
//
return "No";
}
[풀이 - Sherlock and Squares]
더보기
int squares(int a, int b)
{
int result = 0;
//
for(int i = a ; i <= b ;)
{
double square = sqrt(i);
//
if(square - (int)square > 0)
{
++i;
continue;
}
else
{
++result;
//
int next = (int)square + 1;
if(next * next <= b)
i = next * next;
else
break;
}
}
//
return result;
}
[풀이 - Library Fine]
더보기
int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2)
{
int yearRate = 10000;
int monthRate = 500;
int dayRate = 15;
//
int dy = y1 - y2;
int dm = m1 - m2;
int dd = d1 - d2;
//
if(dy > 0)
return dy * yearRate;
else if(dy < 0)
return 0;
//
if(dm > 0)
return dm * monthRate;
else if(dm < 0)
return 0;
//
if(dd > 0)
return dd * dayRate;
else
return 0;
}