[지코바] solved.ac CLASS 2 Part 1
1018) 체스판 다시 칠하기
#include <iostream>
#include <cmath>
char inputBoard[51][51];
int n, m;
int count(int roffset, int coffset) {
int countA = 0;
int countB = 0;
char first = inputBoard[roffset][coffset];
for(int index = roffset; index < roffset + 8; index++) {
for(int subIndex = coffset; subIndex < coffset + 8; subIndex++) {
if (index % 2 == 0) {
if (subIndex % 2 == 0) {
if (inputBoard[index][subIndex] != first) countA++;
else countB++;
} else {
if (inputBoard[index][subIndex] == first) countA++;
else countB++;
}
} else {
if (subIndex % 2 == 0) {
if (inputBoard[index][subIndex] == first) countA++;
else countB++;
} else {
if (inputBoard[index][subIndex] != first) countA++;
else countB++;
}
}
}
}
return fminl(countA, countB);
}
int main() {
std::cin >> n >> m;
int result = 64;
for(int index = 0; index < n; index++) {
for(int subIndex = 0; subIndex < m; subIndex++) {
std::cin >> inputBoard[index][subIndex];
}
}
for(int index = 0; index < n - 8 + 1; index++) {
for(int subIndex = 0; subIndex < m - 8 + 1; subIndex++) {
result = fminl(result, count(index, subIndex));
}
}
std::cout << result;
return 0;
}
1085) 직사각형에서 탈출
#include <iostream>
#include <cmath>
int x, y, w, h;
int direction[4];
int minLengthFromEdge() {
int minLength;
direction[0] = x;
direction[1] = y;
direction[2] = w-x;
direction[3] = h-y;
minLength = direction[0];
for (int i=1; i<4; i++) {
minLength = fminl(minLength, direction[i]);
}
return minLength;
}
int main(int argc, char *argv[]) {
std::cin >> x >> y >> w >> h;
std::cout << minLengthFromEdge();
return 0;
}
1181) 단어 정렬
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int n;
std::vector<std::string> words;
bool compWords(std::string first, std::string second) {
int firstLength = first.length();
int secondLength = second.length();
if (firstLength == secondLength) {
for (int i=0; i<firstLength; i++) {
if (first[i] != second[i]) {
return first[i] < second[i];
}
}
}
return firstLength < secondLength;
}
void sortWords() {
sort(words.begin(), words.end(), compWords);
words.erase(unique(words.begin(), words.end()), words.end());
}
int main(int argc, char *argv[]) {
std::cin >> n;
for(int i=0; i<n; i++) {
std::string str;
std::cin >> str;
words.push_back(str);
}
sortWords();
for(int i=0; i<words.size(); i++) {
std::cout << words[i] << '\n';
}
return 0;
}
1259) 팰린드롬수
#include <iostream>
#include <string>
bool isPalindromeInteger(std::string integer) {
int length = integer.length();
for (int i=0; i<length/2; i++) {
if (integer[i] != integer[length - (i + 1)]) {
return false;
}
}
return true;
}
int main(int argc, char const *argv[])
{
std::string integer;
while (true) {
std::cin >> integer;
if (integer == "0") break;
std::string message = isPalindromeInteger(integer) ? "yes\n": "no\n";
std::cout << message;
}
return 0;
}
Author And Source
이 문제에 관하여([지코바] solved.ac CLASS 2 Part 1), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@onehunnitconst/지코바-solved.ac-CLASS-2-Part-1저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)