백준알고리즘 5

[백준 17478] c++ - cout 대신 printf문 사용 / c_str()

속도 문제때문에 #include scanf, printf문을 사용하고 있었는데 이번 문제에서는 오히려 printf문을 쓰니까 더 헷갈렸다.string str은 c++의 string 형태이기 때문에 printf문(C함수)에서는 c_str()를 이용해서 출력할 수 있다.//백준 17478 - 재귀함수가 뭔가요?#include #include using namespace std;void recur(int n, string str){ printf("%s\"재귀함수가 뭔가요?\"\n", str.c_str()); if(n == 0){ printf("%s\"재귀함수는 자기 자신을 호출하는 함수라네\"\n", str.c_str()); printf("%s라고 답변하였지.\n", str.c_str()); ..

Algorithm/Baekjoon 2024.07.15

[백준 1920] c++/ 시간 초과 해결 - endl보다 \n가 속도 빠름

//백준 1920 - 수 찾기#include #include using namespace std;int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; // 자연수 개수 입력받기 int* num = new int[n]; for(int i = 0; i > num[i]; sort(num, num + n); int m, find; cin >> m; for(int i = 0; i > find; cout  시간 초과 날까봐 일부러 아래와 같이 작성했는데도 시간 초과가 나왔다.ios_base::sync_with_stdio(false);  cin.tie(NULL); 원인은 endl이었다. endl은 버퍼를 ..

Algorithm/Baekjoon 2024.07.13

[백준 4344] C++ - 소수점 출력하기

c++ 실행 가능 사이트 myCompiler - C, C++, 자바, 파이썬, 고, NodeJS 및 기타 언어를 위한 온라인 IDEmyCompiler를 사용하여 자주 사용하는 프로그래밍 언어를 온라인으로 실행하세요.원하는 프로그래밍 언어로 코드를 편집, 컴파일 및 실행할 수 있는 간단하고 사용하기 쉬운 IDEwww.mycompiler.io -C++ 소수점 출력하는 법  [C++] 소수점 자릿수 정하기소수점 자릿수 정하기 파이썬과 C는 간단하게 소수점 자릿수를 정하여 출력할 수 있지만 C++은 생각보다 번거롭다. precision을 이용하며, 소수점 이하는 반올림된다. #include int main() { const double PI =wn42.tistory.com //백준 4344 - 평균은 넘겠지#i..

Algorithm/Baekjoon 2024.07.09
728x90