반응형

Programming 298

백준 10773 제로 [c++]

#include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k;//k의 수 만큼 입력받는다 int sum = 0; int num; stack s;//stack 선언 cin >> k;//k입력 for (int i = 0; i > num;//num입력 if (num != 0)//num이 0 이아니면 스택에 num을 추가 s.push(num); else s.pop();//num이 0이면 스택의 top 데이터 삭제 } while (!s.empty())//스택이 empty가 ..

백준 1427 소트인사이드 [c++]

#include #include #include #include using namespace std; bool cmp(int a, int b)//sort함수에서 내림차순으로 정렬을 위한 함수 { return b > n; int* arr = new int[n.size()];//값을 저장할 배열 for (int i = 0; i < n.size(); i++)//입력받은 n을 arr배열에 숫자로 저장 { arr[i] = n[i]-'0';//아스키코드상에서 문자1은 49이며, 문자0은 48입니다. 그러므로 문자열숫자 - '0'을 하면 정수형숫자를..

백준 1292 쉽게 푸는 문제 [c++]

#include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b;//첫째줄에 시작과 끝을 나타내는 변수 int idx = 2;//인덱스로 사용할 변수 int sum = 0;//합계로 사용할 변수 cin >> a >> b;//a,b 입력받기 int arr[1001] = { 0, };//수열을 저장할 배열 for (int i = 1; i < 1001; i++)//1부터 1000까지 반복 { if (i == 1)//1일 경우에는 한개만 저장하면 됨으로 저장 arr[i] = i; else //그외의 경우 2부터 { for (int j = 0; j..

백준 10984 내 학점을 구해줘 [c++]

#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.fixed;//소수점고정을 위해 사용 cout.precision(2); int t; cin >> t;//학기의수 int* arr = new int[t];//총 학점을 저장할 배열 double* gpaArr = new double[t];//총 평점을 저장할 배열 int n;//과목의수 int temp[10] = { 0, };//학점을 입력받을 배열 double temp2[10] = { 0, };//성적을 입력받을 배열 int intSum = 0; double doubleSum = 0.0; for (int i = 0;..

백준 2748 피보나치수2 [c++]

#include using namespace std; long long arr[90] = { 0,};//n이 90까지 입력될 수 있기때문에 long long 으로 선언해야 한다. long long func(int n)//재귀함수를 사용하여 피보나치수를 구하고 구한 피보나치 수를 배열에 저장한다. { if (n == 0 || n == 1) return arr[n]; else if (arr[n] == 0) arr[n] = func(n - 1) + func(n - 2); return arr[n]; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; arr[0] = 0;//0번째 피보나치수는 0 ar..

반응형