c++ 1282 : 제곱수 만들기
c++ 1282 : 제곱수 만들기
2020.11.07문제 설명 nn이 입력되면 kk를 빼서 제곱수를 만들 수 있는 kk를 구하고, 그 제곱수에 루트를 씌운 수(제곱근) tt를 구하여라. 이 때 k는 여러가지가 될 수 있는데 가장 작은 k를 출력한다. 입력 nn이 입력된다.(0tt를 출력한다. 이 때 kk는 여러가지가 될 수 있는데 가장 작은 kk를 출력한다. 입력 예시 34 출력 예시 9 5 도움말 3434에서 99를 빼면 2525이고, 2525의 제곱근은 55이다. #include #include using namespace std; int main() { int n; cin >> n; for (int i = n; i >= 0; --i) { int a = sqrt(i); double b = sqrt(i); if (a == b) { cout
c++ 1278 : 자릿수 계산
c++ 1278 : 자릿수 계산
2020.11.07문제 설명 어떤 숫자가 입력되면 그 숫자가 몇 자릿수 숫자인지 알아내는 프로그램을 작성하시오. 예) 7 ----> 1 (1자릿수) 10 ----> 2 (2자릿수) 4322 ----> 4 (4자릿수) 입력 1이상의 자연수 n이 입력된다. (n은 int 범위) 출력 그 숫자가 몇 자릿수 인지 출력하시오. 입력 예시 932 출력 예시 3 #include #include using namespace std; int main() { string str; cin >> str; cout
c++ 1277 : 몇 번째 데이터 출력하기
c++ 1277 : 몇 번째 데이터 출력하기
2020.11.07#include #include using namespace std; int main() { int n; cin >> n; vector array; for (int i = 0; i > input; array.push_back(input); } cout
c++ 1275 : k 제곱 구하기
c++ 1275 : k 제곱 구하기
2020.11.07#include #include using namespace std; int main() { int n, k; cin >> n >> k; long long int result = pow(n, k); cout
c++ 비교 연산자 오버로딩 하기
c++ 비교 연산자 오버로딩 하기
2020.11.05#include #include #include using namespace std; class Cents { private: int m_cents; public: Cents(int cents = 0) { m_cents = cents; } int getCents() const { return m_cents; } int& getCents() { return m_cents; } friend std::ostream& operator
c++ 단항 연산자 오버로딩 하기
c++ 단항 연산자 오버로딩 하기
2020.11.05#include using namespace std; class Cents { private: int m_cents; public: Cents(int cents= 0) { m_cents = cents; } int getCents() const { return m_cents; } int& getCents() { return m_cents; } }; Cents 클래스를 만들었습니다. 처음으로 할 것은 입출력 operator 를 오버로딩하는 것 입니다. friend std::ostream& operator
c++ 1274 : 소수 판별
c++ 1274 : 소수 판별
2020.11.04소수를 구하는 방법에는 여러가지가 있지만 저는 가장 기본적인 방식으로 풀어봤습니다. #include using namespace std; int main() { int n; cin >> n; for (int i = 1; i < n; ++i) { if (n % i == 0 && i != 1) { cout
c++ 1273 : 약수 구하기
c++ 1273 : 약수 구하기
2020.11.04숫자가 주어졌을때 for 문을 돌면서 i 값으로 나눴을때 나머지가 0일경우가 약수입니다. #include using namespace std; int main() { int n; cin >> n; for (int i = 1; i
Qt - Hello world
Qt - Hello world
2020.11.04처음 시작하는 Qt 이기 때문에 다른방법보다 더쉬운 Qt creater 를 사용해서 만들어 보겠습니다. New project를 누르고 Qt widgets 을 선택합니다. 파일이 생성될 경로를 지정해주시고 파일이름을 설정합니다. Base class 는 app type을 지정하는데 QmainWindow (menubar, status bar, tool bar) 기본구조 Qwidget 조금더 간단한 형태 dialog 등등 form file -> Ui의 대한 정보를 담는 파일 입니다. Kits 는 컴파일러 의 종류를 결정 하는 것입니다. 저는 64bit 로 선택하였습니다. gcc 나 clang 같은걸 추가해서 사용 할 수도 있습니다. 기본적인 틀이 잡힌 파일이 생성되었습니다. .pro 라는 파일은 Qt에서 사용하..
C++ 1272 : 기부
C++ 1272 : 기부
2020.11.03#include using namespace std; int main() { int a(0), b(0); cin >> a >> b; if (a % 2 == 0) a *= 5; else a = (a + 1) * 5 / 10; if (b % 2 == 0) b *= 5; else b = (b + 1) *5 / 10; cout
c++ 1271 : 최대값 구하기
c++ 1271 : 최대값 구하기
2020.11.03#include #include #include using namespace std; int main() { int x = 0; vector array; cin >> x; for (int i = 0; i > input_num; array.push_back(input_num); } sort(array.begin(), array.end()); cout
C++ 1270 : 1의 개수는?
C++ 1270 : 1의 개수는?
2020.11.03#include using namespace std; int main() { int x, cnt = 0; cin >> x; for (int i = 1; i