본문 바로가기

C++25

C++ 2908 상수 문제를 풀고 다른 풀이를 좀 찾아보니 마지막 인덱스부터 차례로 대소비교를 해서 푼 사람들이 많았다. 나는 세자리 숫자로 제한이 돼있어서 그냥 0번째 인덱스와 2번째 인덱스를 바꾼 후 stoi를 통해 string을 int 형으로 바꿔주고 대소비교를 했다. 사실 세자리라 문제는 없었지만 자리수가 커질 수도 있다고 가정하면 마지막 인덱스부터 대소비교를 하는 것이 맞는 풀이 같다. #include #include using namespace std; int main() { string numA, numB; cin >> numA>> numB; char tempA = numA[0]; numA[0] = numA[2]; numA[2] = tempA; char tempB = numB[0]; numB[0] = numB[2.. 2022. 6. 21.
C++ 2577 숫자의 개수 #include #include using namespace std; int main() { int A, B, C; cin >> A >> B >> C; string result = to_string( A * B * C); string num = "0123456789"; int count[10]; //count 배열 다 0으로 초기화 for (int i = 0; i < 10; i++) { count[i] = 0; } for (int i = 0; i < num.length(); i++) { while (result.find(num[i]) !=string::npos) { count[i]++; result = result.substr(result.find(num[i]) + 1); } result = to_str.. 2022. 6. 20.
c++ 1152 단어의 개수 #include #include using namespace std; int main() { string temp; getline(cin, temp); int count=1; for (int i = 0; i temp 따로 안써줘도 입력까지 받아줌 이 경우 #include 을 해줘야함. 처음에 안해주고 계속 getline이 안써져서 고생했다. 2. 문제에 따라 첫자리와 끝자리가 공백인 경우를 고려해줘야 한다. 2022. 6. 15.
레벨테스트 답변 피보나치 수열 #include #include using namespace std; int Fi(int num) { if (num == 1) return 1; else if (num == 2) return 1; else return Fi(num - 1) + Fi(num - 2); } void main() { int num; cin >> num; cout value == value) { while (currentNode->next != tail) { currentNode = currentNode->next; } delete(tail); tail = currentNode; } else { for (int i = 0; i < SearchPosition(value) - 2; i++) { currentNode =.. 2022. 5. 2.