top of page

게시판 게시물

yubinkong
2022년 2월 15일
In 소스 코드 제출
/* #include <stdio.h> #include <malloc.h> int* solution(int n, long long left, long long right) { int* answer=(int*)malloc(sizeof(int)*(right-left+1)); long long int i, j, div=0, mod=0; /* int x1=left/n,y1=left%n; int x2=right/n,y2=right%n; */ /*for(j=y1;j<n;j++) answer[x1*n+j+1-left]=0; */ /* for(j=y1;j<x1;j++) { answer[x1*n+j-left]=i+1; } for(j=x1;j<n;j++) { answer[x1*n+j-left]=j+1; } for(i=x1+1;i<x2;i++) { for(j=0;j<i;j++) answer[i*n+j-left]=i+1; for(j=i;j<n;j++) answer[i*n+j-left]=j+1; } for(j=0;j<=y2;j++) { if(y2==n-1) { answer[x2*n+j-left]=i+1; } else { answer[x2*n+j-left]=i+j+1; } } */ /* for(i=left;i<=right;i++) { div=i/n; mod=i%n; //printf("%d %d %d\n",i-left,div,mod); if(div>=mod) { answer[i-left]=div+1; //*answer=answer[i-left]; } else { answer[i-left]=mod+1; //*answer=answer[i-left]; } } return answer; } */ #include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> int solution(char* s) { int answer=0; int length=strlen(s); int i, subLength, left, right; for(i=0;i<length;i++) { for(subLength = length;subLength>answer;subLength--) { left = i; right = i + subLength - 1; while(left<right && s[left] == s[right]) { left++; right--; } if(left>=right && answer < subLength) { answer = subLength; } } } return answer; }
0
0
2
yubinkong
2022년 2월 12일
In 소스 코드 제출
#include <stdio.h> #include <string.h> int max(int a, int b) { if(a>b) return a; else return b; } int palindrome(const char* s, int left, int right) { int answer=0, len; len=strlen(s); while(left>=0&&right<len) { if(s[left]==s[right]) { left--; right++; answer+=2; } else break; } return answer; } int solution(const char* s) { int i, a=0, b=0, answer=1, len; len=strlen(s); for(i=0;i<len;i++) { if(len==1) answer=1; else { answer=max(palindrome(s, i, i+1), palindrome(s, i, i+2)); printf("%d ", answer+1); } //answer=palindrome(s, i, i+1); //answer=palindrome(s, i, i+2); } return answer; } #include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> int solution(char* s) {int answer = 0;int length = strlen(s);int i, subLength, left, right;for(i=0;i<length;i++) {for(subLength = length;subLength>answer;subLength--) {left = i;right = i + subLength - 1;while(left<right && s[left] == s[right]) {left++;right--;}if(left>=right && answer < subLength) {answer = subLength;}}}return answer;} #include <stdio.h> #include <stdbool.h> #include <stdlib.h> #define MAX(a, b) (a>b)?(a):(b) int map[2500][2500];int match(char *arr, int s, int e){if(s>=e) return 0;int left = s, right = e;int count = 0;if(map[s][e] !=0) return map[s][e];while(left<right) {if(arr[left]==arr[right]) {count++;left++;right--;}else break;}if(left == right)return count*2+1;else if (left > right)return count*2;elsereturn map[s][e] = MAX(match(arr, s+1, e), match(arr, s, e-1));}int solution(char* s) {int answer = 0;int len = strlen(s);answer = match(s, 0, len-1);return answer==0?1:answer;} #include <stdio.h> #include <stdbool.h> #include <stdlib.h> // a_len은 배열 a의 길이입니다.// edges_rows는 2차원 배열 edges의 행 길이, edges_cols는 2차원 배열 edges의 열 길이입니다.typedef struct node{int u;int v;}no;no map[6000000+10];long long sum[3000000+10];int count[3000000+10];int visit[3000000+10];long long answer = 0;int compare(const void *a, const void *b){no *temp1 = (no *)a;no *temp2 = (no *)b;if(temp1->u> temp2->u)return 1;else if(temp1->u < temp2->u)return -1;else{if(temp1->v > temp2->v)return 1;else if(temp1->v < temp2->v)return -1;elsereturn 0;}}void DFS(int node, int parent){int start=0;if(node!=0)start = count[node-1];visit[node]=1;for(int i=start;i< count[node];i++){if(visit[map[i].v]!= 1)DFS(map[i].v, map[i].u);}sum[parent] = sum[parent]+sum[node];answer = answer+llabs(sum[node]);// printf("node:%d sum[%d]:%lld",node, parent, sum[parent]);}long long solution(int a[], size_t a_len, int** edges, size_t edges_rows, size_t edges_cols) {int j=0;long long total=0;for(int i=0;i< a_len;i++){sum[i] = a[i];total = total +sum[i];}if(total !=0)return -1;for(int i=0;i< edges_rows;i++){map[j].u = edges[i][0];map[j].v = edges[i][1];count[map[j].u]++;j++;map[j].u = edges[i][1];map[j].v = edges[i][0];count[map[j].u]++;j++;}//printf("%d",j);qsort(map, j, sizeof(no),compare);for(int i=1;i< a_len+1;i++)count[i] = count[i]+count[i-1];visit[0]=1;DFS(0,0);// for (int i = 0; i < a_len; i++)// if(sum[i]!=0)// answer=-1;return answer;} #include <stdio.h> #include <stdbool.h> #include <stdlib.h> //Memory allocation requires a lot of time in this system.//To avoid timeout, strange design is adopted.#define MAX_A_LEN (300000) struct list{int idx;struct list* next;};struct list* processed_edges[MAX_A_LEN];int visited[MAX_A_LEN];struct list unused_edges[2 * MAX_A_LEN];//Not to use malloc. The number of edges is a_len - 1 but as it is bidirectional it requires at least 2 * (a_len - 1)int idx_unsed_edge;long long dfs(int idx, int a[], struct list* p_edges[], int* visited, long long* couple){long long cur_a = a[idx], change = 0;visited[idx] = 1;for(struct list* node = p_edges[idx]; node; node = node -> next)if(!visited[node -> idx])change += dfs(node -> idx, a, p_edges, visited, &cur_a);*couple += cur_a;return change + llabs(cur_a);}long long solution(int a[], size_t a_len, int** edges, size_t edges_rows, size_t edges_cols) {long long answer, root_value = 0;for(size_t i = 0; i < edges_rows; i++){unused_edges[idx_unsed_edge].idx = edges[i][1];unused_edges[idx_unsed_edge].next = processed_edges[edges[i][0]];processed_edges[edges[i][0]] = &unused_edges[idx_unsed_edge++];unused_edges[idx_unsed_edge].idx = edges[i][0];unused_edges[idx_unsed_edge].next = processed_edges[edges[i][1]];processed_edges[edges[i][1]] = &unused_edges[idx_unsed_edge++];}answer = dfs(0, a, processed_edges, visited, &root_value);return root_value == 0 ? answer : -1;} #include <stdio.h> #include <stdbool.h> #include <stdlib.h> int* solution(int n) {int index = 0;for(int i = 0; i <=n; i++){index+= i;}int* answer = (int*)malloc(index *sizeof(int)); // 이 문제는 3가지 패턴으로 구성되어 있다.int direct_pattern = 1; //1. 방향성 패턴 : 방향이 바뀔때마다 한 방향에 주어지는 주소값 갯수는 1개씩 줄어드므로 이 것을 구현해야 한다.int continue_pattern = 1; //2. 지속성 패턴 : 방향이 바뀌기 전, 적용되는 동일한 패턴.int continue_pattern_buffer = 0;int continue_end = n; // 지속성 패턴이 끝나는 시점. 지속성 패턴이 끝나면 1개씩 빼준다.int cycle_pattern = 0; //3. 사이클 패턴 : 방향이 한바퀴를 돌때, 주소 관련 패턴이 바뀌므로 이 변수로 변함을 적용.// 싸이클 패턴 첫 적용값은 2이므로 식을 자동으로 굴리려면 초기값을 1로 박아, 연산 후 2를 다음 반복문에 적용한다.int value = 1; // 반복문으로 주소값만 방향성에 따라 바꾸고 값은 1씩만 증가시켜 주소에 넣어준다.int address = 0; //최종 적용되는 주소값.for(int i = 0; i < n ;i++){ //i는 주소값 증가와 value값 증가이다.int temp[n];for(int j = 0; j < continue_end;j++){if(direct_pattern%3 == 1){continue_pattern = j == 0 ? continue_pattern + cycle_pattern : continue_pattern; // 최초 시작시 싸이클 패턴 더해주고... 2싸이클부터는 돌아가나? 뭐하지?continue_pattern = j != 0 ? continue_pattern + j + cycle_pattern : continue_pattern;address = continue_pattern;}else if(direct_pattern%3 == 2){ // 싸이클 패턴 필요 없음.continue_pattern++;address = continue_pattern;}else if(direct_pattern%3 == 0){ // 싸이클 패턴 필요 없음.continue_pattern = continue_pattern - (n - cycle_pattern/2 - j);address = continue_pattern;}//address = address + continue_pattern; //변경된 패턴을 주소에 더 한다.*(answer + address - 1) = value; //패턴이 적용된 주소에 새 value값을 적용한다.value++;}cycle_pattern = direct_pattern % 3 == 0 ? cycle_pattern+2 : cycle_pattern; //방향성 패턴이 value = 1로 회귀전, cycle_pattern증가.(2개씩)direct_pattern = direct_pattern % 3 == 0 ? direct_pattern /3: direct_pattern + 1; //방향성 패턴이 4가 되면, value = 1로 회귀.continue_end--; //지속성 패턴 초기화.}//*answer = *(answer+2);return answer;} #include <stdio.h> #include <stdbool.h> #include <stdlib.h> int* solution(int n) {// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.int* answer = (int*)calloc(n * (n+1) / 2, sizeof(int));int temp[n][n];int re = n;int col = 0, row = -1;int a = 0, b = 0, c = 0, num = 0;for(a = 0;a < re;a++){b = re - a;if(c % 3 == 0){while (b-- > 0)temp[++row][col] = ++num;}else if(c % 3 == 1){while (b-- > 0)temp[row][++col] = ++num;}else{while (b-- > 0)temp[--row][--col] = ++num;}c++;}int count = 0;for(int i = 0;i < n;i++){for(int j = 0;j <= i;j++)answer[count++] = temp[i][j];}return answer;}
0
0
5
yubinkong
2022년 2월 09일
In 소스 코드 제출
#include <stdio.h> #include <malloc.h> int* solution(int n, long long left, long long right) { int* answer=(int*)malloc(sizeof(int)*(right-left+1)); int i, j, div=0, mod=0; int x1=left/n,y1=left%n; int x2=right/n,y2=right%n; /*for(j=y1;j<n;j++) answer[x1*n+j+1-left]=0; */ for(j=y1;j<x1;j++) { answer[x1*n+j-left]=i+1; } for(j=x1;j<n;j++) { answer[x1*n+j-left]=j+1; } for(i=x1+1;i<x2;i++) { for(j=0;j<i;j++) answer[i*n+j-left]=i+1; for(j=i;j<n;j++) answer[i*n+j-left]=j+1; } for(j=0;j<=y2;j++) { if(y2==n-1) { answer[x2*n+j-left]=i+1; } else { answer[x2*n+j-left]=i+j+1; } } /* for(i=left;i<=right;i++) { div=i/n; mod=i%n; //printf("%d %d %d\n",i-left,div,mod); if(div>=mod) { answer[i-left]=div+1; //*answer=answer[i-left]; } else { answer[i-left]=mod+1; //*answer=answer[i-left]; } } */ return answer; }
0
0
2
yubinkong
2022년 2월 08일
In 소스 코드 제출
/* n^2 배열 자르기 #include <stdio.h> #include <malloc.h> int* solution(int n, long long left, long long right) { int* answer=(int*)malloc(sizeof(int)*(right-left+1)); int i, j, div=0, mod=0; for(i=left;i<=right;i++) { div=i/n; mod=i%n; if(div>=mod) { answer[i-left]=div+1; *answer=answer[i-left]; } else { answer[i-left]=mod+1; *answer=answer[i-left]; } } return answer; } */ #include <stdio.h> #include <malloc.h> #include <string.h> #define SIZE 1001 char stack[SIZE]; int top=-1; void push(char data) { if(top==SIZE-1) return; stack[++top]=data; } char pop() { if(top==-1) return 0; return stack[top--]; } int isright(char* s) { int i, cnt=0; top=-1; for(i=0;s[i]!=0;i++){ if(s[i]=='(') push(s[i]); else if(s[i]==')') pop(); } if(top==-1) return 1; else return 0; } bool solution(const char* s) { bool answer=true; int i, len=0; strcpy(strc, s); for(i=0;s[i]!=0;i++) { if(isright(strc+i)==1) answer++; strc[len+i]=strc[i]; strc[len+i+1]=0; } return answer; }
0
0
1
yubinkong
2022년 1월 25일
In 소스 코드 제출
/* #include <stdio.h> int solution(const char* s) { int i, a=0, b=0, answer=0; for(i=0;s[i]!=0;i++) { a++; if(a%2==0) { a-i=b; if(s[i]==s[b]) } } printf("%d", a); return answer; } */ /* #include <stdio.h> #include <malloc.h> int* solution(int n) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)calloc(n * (n+1) / 2, sizeof(int)); //int** arr=(int**)malloc(sizeof(int*)*n*(n+1)/2); int i, j, a=1, arr[1001][1001]; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { arr[i][j]=a++; } } for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf("%d ", arr[i][j]); } printf("\n"); } return answer; } */ /* #include <stdio.h> #include <string.h> int max(int a, int b) { if(a>b) return a; else return b; } int palindrome(const char* s, int left, int right) { int answer=0, len; len=strlen(s); if(right-left==1) answer=0; else answer=1; while(left>=0&&right<len) { if(s[left]==s[right]) { left--; right++; answer+=2; } else break; } return answer; } int solution(const char* s) { int i, j, a=0, b=0, answer=1, len; len=strlen(s); for(i=0;i<len;i++) { //if(len==1) answer=1; //else answer=max(palindrome(s, i, i+1), palindrome(s, i, i+2)); answer=palindrome(s, i, i+1); //answer=palindrome(s, i, i+2); } return answer; } */
0
0
2
yubinkong
2022년 1월 22일
In 소스 코드 제출
/* #include <stdio.h> #include <malloc.h> int* solution(int n, long long left, long long right) { int* answer=(int*)malloc(sizeof(int)*(right-left+1)); int* a=(int*)malloc(sizeof(int)*(right-left+1)); int i, j, div=0, mod=0; for(i=left;i<=right;i++) { div=i/n; mod=i%n; if(div>=mod) a[i]=div; else a[i]=mod; //*a=*(a+i)+1; *answer=a[i]+1; printf("%d ", *answer); } //printf("%d ", *answer); return answer; } */ /* #include <stdio.h> #include <malloc.h> #define SIZE 10000000 int solution(int n, long long left, long long right) { int a[SIZE], i, j, div=0, mod=0; for(i=left;i<=right;i++) { div=i/n; mod=i%n; if(div>=mod) a[i]=div; else a[i]=mod; a[i]=a[i]+1; printf("%d ", a[i]); } return a; } */ /* #include <stdio.h> #include <stdbool.h> #include <stdlib.h> void Least(int **queries) { } int* solution(int rows, int columns, int **queries, size_t queries_row_len, size_t queries_col_len) { int* answer = (int*)malloc(1); int i; for(i=0;i<rows;i++) { for(j=0;j<columns;j++) { queries[i][j]=i*j; } } return answer; } */
0
0
3
yubinkong
2022년 1월 20일
In 소스 코드 제출
/* 단순 조합 구하는 방법.. 숫자 여러 개가 랜덤이면 성립 X #include <stdio.h> int answer=0; void pick(int* nums, int nums_len, int size, int k) { int i, j, last, small, item, sum=0, cnt=0; if (k==0) { for(i=1;i<=size;i++) { sum=0; sum+=nums[i]; for(j=0;j<sum;j++) { if(sum%j==0) cnt++; } } if(cnt==2) answer++; printf("\n"); return; } last=size-k-1; if (size==k) small=0; else small=nums[last]+1; for (item=small;item<nums_len;item++) { nums[last+1]=item; pick(nums, nums_len, size, k-1); } } int solution(int nums[], size_t nums_len) { pick(nums, nums_len, 3, 3); return answer; } */ /* 숫자 배열에서 3개 뽑고 더해서 소수 개수 구하는 것이기 때문에 3중 반복문 #include <stdio.h> int answer=0; void isPrime(int sum) { int i, cnt=0; for(i=1;i<=sum;i++) { if(sum%i==0) cnt++; } if(cnt==2) answer++; } int solution(int nums[], size_t nums_len) { int i, j, k, sum=0; for(i=0;i<nums_len;i++) { for(j=i+1;j<nums_len;j++) { for(k=j+1;k<nums_len;k++) { sum=nums[i]+nums[j]+nums[k]; isPrime(sum); } } } return answer; } */ /* 뭔 개판 같은 식이지... if(a<0) return ; else b=a%10; number+=b*10; */ /* 헤맸던 흔적.. #include <stdio.h> #include <stdbool.h> #include <stdlib.h> int* solution(int n, long long left, long long right) { int** a=(int*)malloc(sizeof(int)*n*n); int* answer=(int*)malloc(1); int i, j, div=0, mod=0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i>=j) a[i][j]=i; else a[i][j]=j; } } for(i=left;i<=right;i++) { div=i/n; mod=i%n; } return answer; } */ /* #include <stdio.h> #include <malloc.h> int* solution(int n, long long left, long long right) { int* answer=(int*)malloc(sizeof(int)*(right-left+1)); int i, j, a=0, div=0, mod=0; for(i=left;i<=right;i++) { div=i/n; mod=i%n; if(div>=mod) a=div; else a=mod; printf("%d ", a+1); for(j=0;j<right-left+1;j++) { answer[j]=a+1; } } return answer; } */
0
0
6
yubinkong
2022년 1월 19일
In 소스 코드 제출
/* #include <stdio.h> #include <stdbool.h> #include <stdlib.h> // a_len은 배열 a의 길이입니다. // edges_rows는 2차원 배열 edges의 행 길이, edges_cols는 2차원 배열 edges의 열 길이입니다. void dfs(int** tree, size_t a_len) { int i; for(i=0;i<a_len;i++) { tree[] } } long long solution(int a[], size_t a_len, int** edges, size_t edges_rows, size_t edges_cols) { long long answer=-2; int i, sum=0; for(i=0;i<a_len;i++) { sum+=a[i]; if(sum!=0) { return -1; } dfs(edges, a_len); } return answer; } */ /* void dfs(int** tree, int* a, int a_len) { int i, parent=0, sum=0; for(i=0;i<a_len;i++) { if(tree[a[i]][i]!=parent) dfs(tree, a, a_len); // 부모 노드로 가중치 몰빵시키기 // 가중치 몰빵시킨 것의 절대값 다 더하기 } } */ #include <stdio.h> #include <math.h> long long answer=0; int** tree; void dfs(int a_len, int now, int pre) { int i; for(i=0;i<a_len;i++) { if(tree[now][i]!=pre) { // 이미 방문했던 곳은 제외하고 dfs(a_len, tree[now][i], now); // 0부터 a_len-1까지 탐색하기 } } } long long solution(int a[], size_t a_len, int** edges, size_t edges_rows, size_t edges_cols) { int i, sum=0; for(i=0;i<a_len;i++) { sum+=a[i]; if(sum!=0) { answer=-1; return answer; } } dfs(a_len, 0, 0); return answer; }
0
0
2
yubinkong
2022년 1월 16일
In 소스 코드 제출
/* 최솟값 구하기 // 효율성 없는 코드 ㅠㅠ #include <stdio.h> int solution(int A[], size_t A_len, int B[], size_t B_len) { int i, j, sum=0, tmp=0, answer=0; // A의 오름차순 for(i=0;i<A_len-1;i++) { for(j=0;j<A_len-i-1;j++) { if(A[j]>A[j+1]) { tmp=A[j]; A[j]=A[j+1]; A[j+1]=tmp; } } } // B의 내림차순 for(i=0;i<B_len-1;i++) { for(j=0;j<B_len-i-1;j++) { if(B[j]<B[j+1]) { tmp=B[j]; B[j]=B[j+1]; B[j+1]=tmp; } } } for(i=0;i<A_len;i++) { answer+=A[i]*B[i]; } return answer; } */ /* 최솟값 구하기 // qsort 함수 이용 #include <stdio.h> #include <stdlib.h> // 오름차순 int com_up(const void* a, const void* b) { return(*(int*)a-*(int*)b); } // 내림차순 int com_down(const void* a, const void* b) { return(*(int*)b-*(int*)a); } int solution(int A[], size_t A_len, int B[], size_t B_len) { int i, answer=0; qsort((int *)A, A_len, sizeof(int), com_up); qsort((int *)B, B_len, sizeof(int), com_down); for(i=0;i<A_len;i++) { answer+=A[i]*B[i]; } return answer; } */ /* 버려진 나의 괄호 회전하기 코드... for(i=0;s[i]!=0;i++) { if(len%2!=0) { answer=0; return answer; } if((s[i]=='('&&s[i+1]==')')||(s[i]=='['&&s[i+1]==']')||(s[i]=='{'&&s[i+1]=='}')) answer=len/2; if(s[i]=='('||s[i]=='['||s[i]=='{') push(s[i]); else if(s[i]==')') { if(s[i-1]=='(') pop(); else { answer=0; return answer; } } else if(s[i]==']') { if(s[i-1]=='[') pop(); else if(s[i-1]=='') else { answer=0; return answer; } } else if(s[i]=='}') { if(s[i-1]=='{') pop(); else { answer=0; return answer; } } } */ /* #include <stdio.h> #include <malloc.h> #include <string.h> #define SIZE 1001 char stack[SIZE]; int top=-1; void push(char data) { if(top==SIZE-1) return; stack[++top]=data; } char pop() { if(top==-1) return 0; return stack[top--]; } int isright(char* s) { printf("%s\n", s); int i, cnt=0; for(i=0;s[i]!=0;i++){ if(s[i]=='('||s[i]=='['||s[i]=='{') push(s[i]); else if(s[i]==')') { if(s[i-1]=='(') { pop(); cnt++; } } else if(s[i]==']') { if(s[i-1]=='[') { pop(); cnt++; } } else if(s[i]=='}') { if(s[i-1]=='{') { pop(); cnt++; } } } return cnt; } int solution(const char* s) { int i, len=0, answer=0, a=0, b=0, c=0, d=0, e=0, f=0; len=strlen(s); char* strc=(char*)malloc(sizeof(char)*len*2); strcpy(strc, s); for(i=0;s[i]!=0;i++) { if(s[i]=='(') a++; else if(s[i]==')') b++; else if(s[i]=='[') c++; else if(s[i]==']') d++; else if(s[i]=='{') e++; else if(s[i]=='}') f++; } if(a!=b||c!=d||e!=f||len%2!=0) return 0; for(i=0;s[i]!=0;i++) { answer=isright(strc+i); strc[len+i]=strc[i]; strc[len+i+1]=0; } return answer; } */ /* #include <stdio.h> #include <malloc.h> #include <string.h> #define SIZE 1001 char stack[SIZE]; int top=-1; void push(char data) { if(top==SIZE-1) return; stack[++top]=data; } char pop() { if(top==-1) return 0; return stack[top--]; } int isright(char* s) { int i, cnt=0; top=-1; for(i=0;s[i]!=0;i++){ if(s[i]=='('||s[i]=='['||s[i]=='{') push(s[i]); else if(s[i]==')') { if(top==-1||stack[top]!='(') return 0; else pop(); } else if(s[i]==']') { if(top==-1||stack[top]!='[') return 0; else pop(); } else if(s[i]=='}') { if(top==-1||stack[top]!='{') return 0; else pop(); } } if(top==-1) return 1; else return 0; } int solution(const char* s) { int i, len=0, answer=0, a=0, b=0, c=0, d=0, e=0, f=0; len=strlen(s); char* strc=(char*)malloc(sizeof(char)*len*2); strcpy(strc, s); for(i=0;s[i]!=0;i++) { printf("%s %d\n",strc+i,isright(strc+i)); if(isright(strc+i)==1) answer++; strc[len+i]=strc[i]; strc[len+i+1]=0; } return answer; } */
0
0
5
yubinkong
2022년 1월 15일
In 소스 코드 제출
/* #include <stdio.h> #define MAX_TREE 300001 int main() { int a[MAX_TREE], i, n, sum=0; scanf("%d", &n); for(i=0;i<n;i++) { scanf("%d", &a[i]); sum+=a[i]; if(sum=!0) { return -1; } } return 0; } */ /* #include <stdio.h> #include <stdbool.h> #include <stdlib.h> // a_len은 배열 a의 길이입니다. // edges_rows는 2차원 배열 edges의 행 길이, edges_cols는 2차원 배열 edges의 열 길이입니다. long long solution(int a[], size_t a_len, int** edges, size_t edges_rows, size_t edges_cols) { long long answer=-2; int i, sum=0; for(i=0;i<a_len;i++) { sum+=a[i]; if(sum!=0) { return -1; } edges[edges_rows][edges_cols] } return answer; } */ /* #include <stdio.h> #include <string.h> int main() { char zero='0'; int num; num=zero-'0'; printf("%d", num); } */ /* #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int i, answer=0; char num[10]={'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'}; for(i=0;i<=9;i++) { num[i]=i; printf("%s", num[i]); } return 0; } */ #include <stdio.h> int solution(int A[], size_t A_len, int B[], size_t B_len) { int i, j, tmp=0, answer=0, min=0; for(i=0;i<A_len-1;i++) { for(j=0;j<A_len-i-1;j++) { if(A[j]>A[j+1]) { tmp=A[j]; A[j]=A[j+1]; A[j+1]=tmp; } } } for(i=0;i<B_len-1;i++) { for(j=0;j<B_len-i-1;j++) { if(B[j]>B[j+1]) { tmp=B[j]; B[j]=B[j+1]; B[j+1]=tmp; } } } for(i=0;i<A_len;i++) { for(j=B_len;j>=0;j--) { tmp=A[i]*B[j]; } answer+=tmp; } return answer; }
0
0
2
yubinkong
2022년 1월 13일
In 소스 코드 제출
/* 4868 #include <stdio.h> typedef struct node_ { int data; node_* child[50]; }node; int main() { int i, n, q, x, a[200001]={}, b, c, d; scanf("%d %d", &n, &q); for(i=0;i<n-1;i++) { scanf("%d", &a[i]); } for(i=0;i<n+q-1;i++) { scanf("%d", &x); if(x==0) { scanf("%d", &b); } else if(x==1) { scanf("%d %d", &c, &d); } } } // 7 2 // 1 // 1 // 2 // 2 // 3 // 5 // 0 7 // 1 2 3 // 0 2 // 0 4 // 0 3 // 1 3 5 // 0 6 */ /* 3274 #include <stdio.h> #define MAX_VERTEX 100001 typedef struct graphNode { int vertex; // 정점 (데이터 필드) struct graphNode* link; // 링크 필드 }graphNode; typedef struct graphType { int n; // 정점 개수 graphNode* arr[MAX_VERTEX]; }graphType; void init(graphType* g) { int v; g->n=0; for(v=0;v<MAX_VERTEX;v++) { g->arr[v]=NULL; } } void insert_vertex(graphType* g, int v) { if(((g->n)+1)>MAX_VERTEX) { return ; } g->n++; } void insert_edge(graphType* g, int u, int v) { graphNode* node; if(u>=g->n||v>=g->n) { printf("error\n"); } node=(graphNode*)malloc(sizeof(graphNode)); node->vertex=v; node->link=g->arr[u]; g->arr[u]=node; } int main() { graphType *g; g=(graphType*)malloc(sizeof(graphType)); init(g); int i, n, q; scanf("%d", &g.n); for(i=0;i<n-1;i++) { scanf("%d %d", ); } scanf("%d", &q); return 0; } */ #include <stdio.h> typedef struct bTree { char data[10]; struct bTree *left, *right; }bTree; void inorder(bTree*) int main() { }
0
0
3
yubinkong
2022년 1월 06일
In 소스 코드 제출
/* #include <stdio.h> typedef struct treeNode { int size; struct treeNode *left, *right; }treeNode; treeNode* createNode(int size, treeNode* left, treeNode* right) { treeNode *root=(treeNode*)malloc(sizeof(treeNode)); root->size=size; root->left=left; root->right=right; return root; } */ /* 1936 int dis(int a, int b) { if(a==b) return 0; if(a>b) return dis(a/2, b)+1; if(a<b) return dis(a, b/2)+1; } int main()19 1 2 3 2 4 5 3 6 7 4 8 -1 5 9 10 6 11 12 7 13 -1 8 -1 -1 9 14 15 10 -1 -1 11 16 -1 12 -1 -1 13 17 -1 14 -1 -1 15 18 -1 16 -1 -1 17 -1 19 18 -1 -1 19 -1 -1 { int a, b; scanf("%d %d", &a, &b); printf("%d", dis(a, b)); return 0; } */ /* 4497 #include <stdio.h> int main() { int i, n, left, right; scanf("%d", &n); for(i=0;i<n;i++) { scanf("%d %d %d", &i+1, &left, &right); } printf("%d %d", ); } */ /* 4868 #include <stdio.h> int main() { int i, n, q, x, a, b, c, d; scanf("%d %d", &n, &q); for(i=0;i<n-1;i++) { scanf("%d", &a); } for(i=0;i<n+q-1;i++) { scanf("%d", &x); if(x==0) { scanf("%d", &b); } else if(x==1) { scanf("%d %d", &c, &d); } } } */ /* 4714 #include <stdio.h> int main() { int i, n, m, a, b; scanf("%d", &n); scanf("%d", &m); for(i=0;i<m;i++) { scanf("%d %d", &a, &b); } } */
0
0
3
yubinkong
2021년 12월 26일
In 소스 코드 제출
/* #include <stdio.h> #define MAX_ELEMENT 100 typedef struct { int heap[MAX_ELEMENT], heap_size; }Heap; Heap *createHeap() { Heap *h=(Heap*)malloc(sizeof(Heap)); h->heap_size=0; return h; } void insertHeap(Heap *h, int item) { int i; h->heap_size=h->heap+1; i=h->heap_size; while((i!=1)&&(item>h->heap[i/2])) { h->heap[i]=h->heap[i/2]; i/=2; } h->heap[i]=item; } int deleteHeap(Heap *h) { int parent, child, item, tmp; item=h->heap[1]; tmp=h->heap[h->heap_size]; h->heap_size=h->heap_size-1; parent=1; child=2; while(child<=h->heap_size) { if((child<h->heap_size)&&(h->heap[child])<h->heap[child+1]) child++; if(tmp>=h->heap[child]) break; else { h->heap[parent]=h->heap[child]; parent=child; child=child*2; } } h->heap[parent]=tmp; return item; } void printHeap(Heap *h) { int i; printf("Heap : "); for(i=1;i<=h->heap_size;i++) { printf("[%d] ", h->heap[i]); } } void main() { int i, n, item; Heap *heap=createHeap(); insertHeap(heap, 10); insertHeap(heap, 45); insertHeap(heap, 19); insertHeap(heap, 11); insertHeap(heap, 96); printHeap(heap); n=heap->heap_size; for(i=1;i<=n;i++) { item=deleteHeap(heap); printf("\n delete : [%d] ", item); } getchar(); } */ /* #include <stdio.h> #define MAX_VERTEX 30 typedef struct { int n, adjMatrix[MAX_VERTEX][MAX_VERTEX]; } graphType; void createGraph(graphType *g) { int i, j; g->n=0; for(i=0;i<MAX_VERTEX;i++) { for(j=0;j<MAX_VERTEX;j++) { g->adjMatrix[i][j]=0; } } } void insertVertex(graphType* g, int v) { if(((g->n)+1)>MAX_VERTEX) { printf("그래프 정점의 개수를 초과하였습니다! "); return ; } g->n++; } void insertEdge(graphType* g, int u, int v) { if(u>=g->n||v>=g->n) { printf("그래프에 없는 정점입니다!"); return ; } g->adjMatrix[u][v]=1; } void printf_adjMatrix(graphType* g) { int i, j; for(i=0;i<g->n;i++) { printf("\n\t\t"); for(j=0;j<g->n;j++) { printf("%2d", g->adjMatrix[i][j]); } } } void main() { int i; graphType *G1, *G2, *G3, *G4; G1=(graphType*)malloc(sizeof(graphType)); G2=(graphType*)malloc(sizeof(graphType)); G3=(graphType*)malloc(sizeof(graphType)); G4=(graphType*)malloc(sizeof(graphType)); createGraph(G1); createGraph(G2); createGraph(G3); createGraph(G4); for(i=0;i<4;i++) { insertVertex(G1, i); } insertEdge(G1, 0, 1); insertEdge(G1, 0, 3); insertEdge(G1, 1, 0); insertEdge(G1, 1, 2); insertEdge(G1, 1, 3); insertEdge(G1, 2, 1); insertEdge(G1, 2, 3); insertEdge(G1, 3, 0); insertEdge(G1, 3, 1); insertEdge(G1, 3, 2); printf("\nG1의 인접행렬"); printf_adjMatrix(G1); for(i=0;i<3;i++) { insertVertex(G2, i); } insertEdge(G2, 0, 1); insertEdge(G2, 0, 2); insertEdge(G2, 1, 0); insertEdge(G2, 1, 2); insertEdge(G2, 2, 0); insertEdge(G2, 2, 1); printf("\n\nG2의 인접행렬"); printf_adjMatrix(G2); for(i=0;i<4;i++) { insertVertex(G3, i); } insertEdge(G3, 0, 1); insertEdge(G3, 0, 3); insertEdge(G3, 1, 2); insertEdge(G3, 1, 3); insertEdge(G3, 2, 3); printf("\n\nG3의 인접행렬"); printf_adjMatrix(G3); for(i=0;i<3;i++) { insertVertex(G4, i); } insertEdge(G4, 0, 1); insertEdge(G4, 0, 2); insertEdge(G4, 1, 0); insertEdge(G4, 1, 2); printf("\n\nG4의 인접행렬"); printf_adjMatrix(G4); getchar(); } */ #include <stdio.h> void selectionSort(int a[], int size) { int i, j, t, min, tmp; printf("정렬할 원소 : "); for(t=0;t<size;t++) printf("%d ", a[t]); printf("\n\n 선택 정렬 수행 \n"); for(i=0;i<size-1;i++) { min=i; for(j=i+1;j<size;j++) { if(a[j]<a[min]) min=j; } tmp=a[i]; a[i]=a[min]; a[min]=tmp; printf("\n%d단계 : ", i+1); for(t=0;t<size;t++) { printf("%3d ", a[t]); } } } int main() { int n, size=0, *arr; FILE *fp; fp=fopen("data.txt", "r"); arr=(int*)malloc(sizeof(int)*size); if(fp==NULL) { printf("ERROR"); return 0; } while(!feof(fp)) { fscanf(fp, "%d", &n); size++; arr[size]=n; } selectionSort(arr[size], size); }
0
0
1
yubinkong
2021년 12월 23일
In 소스 코드 제출
/* #include <stdio.h> int main() { int i, n, a[101]={}; scanf("%d", &n); for(i=0;i<n;i++) { scanf("%d", &a[i]); } for(i=0;i<n;i++) { if(a[i]<a[i+1]) { printf("오름차순"); return 0; } else if(a[i]>a[i+1]) { printf("내림차순"); return 0; } else if(a[i]<a[i+1]) } return 0; } */ /* 2009 #include <stdio.h> int Americano(int n, int k) { if(n<k) return 0; //if(n%k==0) return n/k+n/k/k; return n/k+Americano(n/k+n%k, k); } int main() { int i, n, k; scanf("%d %d", &n, &k); printf("%d", Americano(n, k)); return 0; } */ /* 2033 #include <stdio.h> int main() { int i, k, n, a[100001]={}, start; scanf("%d %d", &k, &n); for(i=0;i<n;i++) { scanf("%d %d", &a[i], &a[i+1]); } scanf("%d", &start); } */ #include <stdio.h> int main() { int i, a, b; scanf("%d", &a); for(i=0;i<a;i++) { if(a%i==0) { printf("%d ", ); } } return 0; }
0
0
2
yubinkong
2021년 12월 19일
In 소스 코드 제출
/* #include <stdio.h> typedef struct treeNode_ { int data; struct treeNode_ *left, *right; }treeNode; treeNode* insertNode(treeNode *p, int x) { treeNode *newNode; if(p==NULL) { newNode=(treeNode*)malloc(sizeof(treeNode*)); newNode->data=x; newNode->left=NULL; newNode->right=NULL; return newNode; } else if(x<p->data) p->left=insertNode(p->left, x); else if(x>p->data) p->right=insertNode(p->right, x); else printf("\nerror\n"); return p; } void deleteNode(treeNode *root, int key) { treeNode *parent, *child, *p, *succ, *succ_parent; parent=NULL; p=root; while((p!=NULL)&&(p->data!=key)) { parent=p; if(key<p->data) p=p->left; else p=p->right; } if(p==NULL) { printf("\nerror\n"); return; } if((p->left==NULL)&&(p->right==NULL)) { if(parent!=NULL) { if(parent!=NULL) { if(parent->left==p) parent->left=NULL; else parent->right=NULL; } else root=NULL; } } else if((p->left==NULL)||(p->right==NULL)) { if(p->left!=NULL) child=p->left; else child=p->right; if(parent!=NULL) { if(parent->left==p) parent->left=child; else parent->right=child; } else root=child; } else { succ_parent=p; succ=p->left; while(succ->right!=NULL) { succ_parent=succ; succ=succ->right; } if(succ_parent->left==succ) succ_parent->left=succ->left; else succ_parent->right=succ->left; p->data=succ->data; p=succ; } free(p); } void displayInorder(treeNode* root) { if(root) { displayInorder(root->left); printf("%d ", root->data); displayInorder(root->right); } } int main() { treeNode *root=NULL; FILE *fp; int n, ro, button; fp=fopen("data.txt", "r"); if(fp==NULL) { printf("file not found\n"); return 0; } fscanf(fp, "%d", &ro); root=insertNode(root, ro); while(!feof(fp)) { fscanf(fp, "%d", &n); insertNode(root, n); } printf("1:출력 2:삽입 3:삭제 4:종료\n"); while(1) { scanf("%d", &button); if(button==1) { printf("이진 트리 출력 : "); displayInorder(root); } else if(button==2) { } else if(button==3) { } else if(button==4) { printf("종료합니다.\n"); return 0; } else { printf("다시 입력하세요.\n"); } } return 0; } */ /* #include <stdio.h> typedef struct treeNode_ { int data; struct treeNode_ *left, *right; }treeNode; treeNode* insertNode(treeNode *p, int x) { treeNode *newNode; if(p==NULL) { newNode=(treeNode*)malloc(sizeof(treeNode)); newNode->data=x; newNode->left=NULL; newNode->right=NULL; return newNode; } else if(x<p->data) p->left=insertNode(p->left, x); else if(x>p->data) p->right=insertNode(p->right, x); else printf("\nerror\n"); return p; } void deleteNode(treeNode *root, int key) { treeNode *parent, *child, *p, *succ, *succ_parent; parent=NULL; p=root; while((p!=NULL)&&(p->data!=key)) { parent=p; if(key<p->data) p=p->left; else p=p->right; } if(p==NULL) { printf("\nerror\n"); return; } if((p->left==NULL)&&(p->right==NULL)) { if(parent!=NULL) { if(parent!=NULL) { if(parent->left==p) parent->left=NULL; else parent->right=NULL; } else root=NULL; } } else if((p->left==NULL)||(p->right==NULL)) { if(p->left!=NULL) child=p->left; else child=p->right; if(parent!=NULL) { if(parent->left==p) parent->left=child; else parent->right=child; } else root=child; } else { succ_parent=p; succ=p->left; while(succ->right!=NULL) { succ_parent=succ; succ=succ->right; } if(succ_parent->left==succ) succ_parent->left=succ->left; else succ_parent->right=succ->left; p->data=succ->data; p=succ; } free(p); } void displayInorder(treeNode* root) { if(root) { displayInorder(root->left); printf("%d ", root->data); displayInorder(root->right); } } int main() { treeNode *root=NULL; FILE *fp; int n, ro, button; fp=fopen("data.txt", "r"); if(fp==NULL) { printf("file not found\n"); return 0; } fscanf(fp, "%d", &ro); root=insertNode(root, ro); while(!feof(fp)) { fscanf(fp, "%d", &n); insertNode(root, n); } printf("1:출력 2:삽입 3:삭제 4:종료\n"); while(1) { scanf("%d", &button); if(button==1) { printf("이진 트리 출력 : "); displayInorder(root); } else if(button==2) { } else if(button==3) { } else if(button==4) { printf("종료합니다.\n"); return 0; } else { printf("다시 입력하세요.\n"); } } return 0; } */ /* 전위 중위 후위 순회 #include <stdio.h> typedef struct treeNode_ { int data; struct treeNode_ *left, *right; }treeNode; treeNode* insertNode(treeNode *p, int x) { treeNode *newNode; if(p==NULL) { newNode=(treeNode*)malloc(sizeof(treeNode)); newNode->data=x; newNode->left=newNode->right=NULL; return newNode; } else if(x<p->data) p->left=insertNode(p->left, x); else if(x>p->data) p->right=insertNode(p->right, x); else printf("\nerror\n"); return p; } void Preorder(treeNode* root) { if(root) { printf("%d ", root->data); Preorder(root->left); Preorder(root->right); } } void Inorder(treeNode* root) { if(root) { Inorder(root->left); printf("%d ", root->data); Inorder(root->right); } } void Postorder(treeNode* root) { if(root) { Postorder(root->left); Postorder(root->right); printf("%d ", root->data); } } int main() { treeNode *root=NULL; FILE *fp; int n, ro, button; fp=fopen("data.txt", "r"); if(fp==NULL) { printf("file not found\n"); return 0; } while(!feof(fp)) { fscanf(fp, "%d", &n); root=insertNode(root, n); } printf("전위 순회 : "); Preorder(root); printf("\n중위 순회 : "); Inorder(root); printf("\n후위 순회 : "); Postorder(root); return 0; } */ #include <stdio.h> #define MAX_ELEMENT 100 typedef struct { int heap[MAX_ELEMENT], heap_size; }Heap; Heap *createHeap() { Heap *h=(Heap*)malloc(sizeof(Heap)); h->heap_size=0; return h; } void insertHeap(Heap *h, int item) { int i; h->heap_size=h->heap+1; i=h->heap_size; while((i!=1)&&(item>h->heap[i/2])) { h->heap[i]=h->heap[i/2]; i/=2; } h->heap[i]=item; } int deleteHeap(Heap *h) { int parent, child, item, tmp; item=h->heap[1]; tmp=h->heap[h->heap_size]; h->heap_size=h->heap_size-1; parent=1; child=2; while(child<=h->heap_size) { if((child<h->heap_size)&&(h->heap[child])<h->heap[child+1]) child++; if(tmp>=h->heap[child]) break; else { h->heap[parent]=h->heap[child]; parent=child; child=child*2; } } h->heap[parent]=tmp; return item; } void printHeap(Heap *h) { int i; printf("Heap : "); for(i=1;i<=h->heap_size;i++) { printf("[%d] ", h->heap[i]); } } void main() { int i, n, item; Heap *heap=createHeap(); insertHeap(heap, 10); insertHeap(heap, 45); insertHeap(heap, 19); insertHeap(heap, 11); insertHeap(heap, 96); printHeap(heap); n=heap->heap_size; for(i=1;i<=n;i++) { item=deleteHeap(heap); printf("\n delete : [%d] ", item); } getchar(); }
0
0
3
yubinkong
2021년 12월 16일
In 소스 코드 제출
/* #include <stdio.h> int main() { tNode* root=NULL; tNode* keyNode=NULL; return 0; } */ /* #include <stdio.h> #include <malloc.h> typedef struct Dnode_ { int data; struct Dnode_ *llink, *rlink; } Dnode; Dnode* init(int k) { Dnode *tmp=(Dnode*)malloc(sizeof(Dnode*)); tmp->data=k; tmp->llink=tmp; tmp->rlink=NULL; return tmp; } void insertNode(Dnode *root, int key) { Dnode *newNode=init(key); if(root==NULL) { root=newNode; return ; } newNode->rlink=root->rlink; root->rlink=newNode; newNode->llink=root; if(newNode->rlink!=NULL) newNode->rlink->llink=newNode; } void printNode() { Dnode *tmp, *head; while(tmp!=NULL) { printf("%d ", tmp->data); tmp=tmp->rlink; } printf("\n"); } int main() { int i, key; Dnode *head=init(key); for(i=0;i<10;i++) { insertNode(head, i); printNode(); } return 0; } */ /* #include <stdio.h> #include <malloc.h> typedef struct Dnode_ { int data; struct Dnode_ *llink, *rlink; } Dnode; Dnode* init(int k) { Dnode *tmp=(Dnode*)malloc(sizeof(Dnode*)); tmp->data=k; tmp->llink=tmp; tmp->rlink=NULL; return tmp; } void searchNode() { Dnode *root; root- } void insertNode(Dnode *root, int key) { Dnode *newNode=init(key); if(root==NULL) { root=newNode; return ; } newNode->rlink=root->rlink; root->rlink=newNode; newNode->llink=root; if(newNode->rlink!=NULL) newNode->rlink->llink=newNode; } void printNode() { Dnode *tmp, *head; while(tmp!=NULL) { printf("%d ", tmp->data); tmp=tmp->rlink; } printf("\n"); } int main() { int i, key; Dnode *head=init(key); return 0; } */ #include <stdio.h> typedef struct treeNode_ { int key; struct treeNode_ *left, *right; }treeNode; treeNode* insertNode(treeNode *p, int x) { treeNode *newNode; if(p==NULL) { newNode=(treeNode*)malloc(sizeof(treeNode*)); newNode->key=x; newNode->left=NULL; newNode->right=NULL; return newNode; } else if(x<p->key) p->left=insertNode(p->left, x); else if(x>p->key) p->right=insertNode(p->right, x); else printf("\nerror\n"); return p; } void deleteNode(treeNode *root, int key) { treeNode *parent, *child, *p, *succ, *succ_parent; parent=NULL; p=root; while((p!=NULL)&&(p->key!=key)) { parent=p; if(key<p->key) p=p->left; else p=p->right; } if(p==NULL) { printf("\nerror\n"); return; } if((p->left==NULL)&&(p->right==NULL)) { if(parent!=NULL) { if(parent!=NULL) { if(parent->left==p) parent->left=NULL; else parent->right=NULL; } else root=NULL; } } else if((p->left==NULL)||(p->right==NULL)) { if(p->left!=NULL) child=p->left; else child=p->right; if(parent!=NULL) { if(parent->left==p) parent->left=child; else parent->right=child; } else root=child; } else { succ_parent=p; succ=p->left; while(succ->right!=NULL) { succ_parent=succ; succ=succ->right; } if(succ_parent->left==succ) succ_parent->left=succ->left; else succ_parent->right=succ->left; p->key=succ->key; p=succ; } free(p); } int main() { }
0
0
2
yubinkong
2021년 8월 26일
In 소스 코드 제출
/* 7-1 import java.util.*; public class Main { public static void main(String[] args) { Vector<Integer> v=new Vector<Integer>(); v.add(5); v.add(4); v.add(-1); v.add(2, 100); System.out.println("벡터 내의 요소 객체 수 : "+v.size()); System.out.println("벡터의 현재 용량 : "+v.capacity()); for(int i=0;i<v.size();i++) { int n=v.get(i); System.out.println(n); } int sum=0; for(int i=0;i<v.size();i++) { int n=v.elementAt(i); sum+=n; } System.out.println("벡터에 있는 정수 합 : "+sum); } } */ /* 7-2 import java.util.*; class Point { private int x, y; public Point(int x, int y) { this.x=x; this.y=y; } public String toString() { return "("+x+", "+y+")"; } } public class Main { public static void main(String[] args) { Vector<Point> v=new Vector<Point>(); v.add(new Point(2, 3)); v.add(new Point(-5, 20)); v.add(new Point(30, -8)); v.remove(1); for(int i=0;i<v.size();i++) { Point p=v.get(i); System.out.println(p); } } } */ /* 7-3 import java.util.*; public class Main { public static void main(String[] args) { ArrayList<String> a=new ArrayList<String>(); Scanner sc=new Scanner(System.in); for(int i=0;i<4;i++) { System.out.print("이름을 입력하세요 >> "); String s=sc.next(); a.add(s); } for(int i=0;i<a.size();i++) { String name=a.get(i); System.out.print(name+" "); } int longestIndex=0; for(int i=1;i<a.size();i++) { if(a.get(longestIndex).length()<a.get(i).length()) longestIndex=i; } System.out.println("\n가장 긴 이름은 : "+a.get(longestIndex)); sc.close(); } } */ /* 7-4 import java.util.*; public class Main { public static void main(String[] args) { Vector<Integer> v=new Vector<Integer>(); v.add(5); v.add(4); v.add(-1); v.add(2, 100); Iterator<Integer> it=v.iterator(); while(it.hasNext()) { int n=it.next(); System.out.println(n); } int sum=0; it=v.iterator(); while(it.hasNext()) { int n=it.next(); sum+=n; } System.out.println("벡터에 있는 정수 합"+sum); } } */ /* 7-5 import java.util.*; public class Main { public static void main(String[] args) { HashMap<String, String> dic=new HashMap<String, String>(); dic.put("baby", "아기"); dic.put("love", "사랑"); dic.put("apple", "사과"); Scanner sc=new Scanner(System.in); while(true) { System.out.print("찾고 싶은 단어는? "); String eng=sc.next(); if(eng.equals("exit")) { System.out.print("종료합니다..."); break; } String kor=dic.get(eng); if(kor==null) System.out.println(eng+"는 없는 단어입니다."); else System.out.println(kor); } sc.close(); } } */ /* 7-6 import java.util.*; public class Main { public static void main(String[] args) { HashMap<String, Integer> sM=new HashMap<String, Integer>(); sM.put("김성동", 97); sM.put("황기태", 88); sM.put("김남윤", 98); sM.put("이재문", 70); sM.put("한원선", 99); System.out.println("HashMap의 요소 개수 : "+sM.size()); Set<String> k=sM.keySet(); Iterator<String> it=k.iterator(); while(it.hasNext()) { String name=it.next(); int score=sM.get(name); System.out.println(name+ " : "+score); } } } */ /* 7-7 import java.util.*; class Student { private int id; private String tel; public Student(int id, String tel) { this.id=id; this.tel=tel; } public int getId() { return id; } public String getTel() { return tel; } } public class Main { public static void main(String[] args) { HashMap<String, Student> map=new HashMap<String, Student>(); map.put("황기태", new Student(1, "010-111-1111")); map.put("이재문", new Student(2, "010-222-2222")); map.put("김남윤", new Student(2, "010-333-3333")); Scanner sc=new Scanner(System.in); while(true) { System.out.print("검색할 이름? "); String name=sc.nextLine(); if(name.equals("exit")) { System.out.print("종료합니다..."); break; } Student st=map.get(name); if(st==null) System.out.println(name+"은 없는 사람입니다."); else System.out.println("id : "+st.getId()+", 전화 : "+st.getTel()); } sc.close(); } } */ /* 7-8 import java.util.*; public class Main { static void printList(LinkedList<String> l) { Iterator<String> iterator=l.iterator(); while(iterator.hasNext()) { String e=iterator.next(); String separator; if(iterator.hasNext()) separator=" -> "; else separator="\n"; System.out.print(e+separator); } } public static void main(String[] args) { LinkedList<String> mL=new LinkedList<String>(); mL.add("트랜스포머"); mL.add("스타워즈"); mL.add("매트릭스"); mL.add(0, "터미네이터"); mL.add(2, "아바타"); Collections.sort(mL); printList(mL); Collections.reverse(mL); printList(mL); int index=Collections.binarySearch(mL, "아바타")+1; System.out.println("아바타는 "+index+"번째 요소입니다."); } } */ /* 7-9 import java.util.*; class GStack<T> { int tos; Object [] stck; public GStack() { tos=0; stck=new Object[10]; } public void push(T item) { if(tos==10) return ; stck[tos]=item; tos++; } public T pop() { if(tos==0) return null; tos--; return (T)stck[tos]; } } public class Main { public static void main(String[] args) { GStack<String> sS=new GStack<String>(); sS.push("seoul"); sS.push("busan"); sS.push("LA"); for(int n=0;n<3;n++) System.out.println(sS.pop()); GStack<Integer> intStack=new GStack<Integer>(); intStack.push(1); intStack.push(3); intStack.push(5); for(int n=0;n<3;n++) System.out.println(intStack.pop()); } } */ /* 7-10 import java.util.*; class GStack<T> { int tos; Object [] stck; public GStack() { tos=0; stck=new Object[10]; } public void push(T item) { if(tos==10) return ; stck[tos]=item; tos++; } public T pop() { if(tos==0) return null; tos--; return (T)stck[tos]; } } public class Main { public static <T> GStack<T> reverse(GStack<T> a) { GStack<T> s=new GStack<T>(); while(true) { T tmp; tmp=a.pop(); if(tmp==null) break; else s.push(tmp); } return s; } public static void main(String[] args) { GStack<Double> gs=new GStack<Double>(); for(int i=0;i<5;i++) gs.push(new Double(i)); gs=reverse(gs); for(int i=0;i<5;i++) System.out.println(gs.pop()); } } */ /* p.434 1 import java.util.*; public class Main { public static void Big(Vector<Integer> v) { int big=v.get(0); for(int i=1;i<v.size();i++) { if(big<v.get(i)) big=v.get(i); } System.out.println("가장 큰 수는 " + big); } public static void main(String[] args) { Vector<Integer> v=new Vector<Integer>(); Scanner sc=new Scanner(System.in); System.out.print("정수(-1이 입력될 때까지) >> "); while(true) { int a=sc.nextInt(); if(a==-1) break; v.add(a); } if(v.size()==0) { System.out.print("아무것도 없음"); return; } Big(v); sc.close(); } } */ /* 5-6 import java.util.*; class Weapon { protected int fire() { return 1; } } class Cannon extends Weapon { protected int fire() { return 10; } } public class Main { public static void main(String[] args) { Weapon weapon; weapon=new Weapon(); System.out.println("기본 무기의 살상 능력은 "+weapon.fire()); weapon=new Cannon(); System.out.println("대포의 살상 능력은 "+weapon.fire()); } } */
0
0
1
yubinkong
2021년 8월 25일
In 소스 코드 제출
/* p.383 1 import java.util.*; class MyPoint { int x, y; public MyPoint(int x, int y) { this.x=x; this.y=y; } public String toString() { return "Point("+x+", "+y+")"; } public boolean equals(Object obj) { MyPoint p=(MyPoint)obj; if(x==p.x&&y==p.y) return true; else return false; } } public class Main { public static void main(String[] args) { MyPoint p=new MyPoint(3, 50); MyPoint q=new MyPoint(4, 50); System.out.println(p); if(p.equals(q)) System.out.println("같은 점"); else System.out.println("다른 점"); } } */ /* p.384 2 import java.util.*; class Circle { int x, y, radius; public Circle(int x, int y, int radius) { this.x=x; this.y=y; this.radius=radius; } public String toString() { return "Circle("+x+", "+y+") 반지름 "+radius; } public boolean equals(Object obj) { Circle a=(Circle)obj; if(x==a.x&&y==a.y) return true; else return false; } } public class Main { public static void main(String[] args) { Circle a=new Circle(2, 3, 5); Circle b=new Circle(2, 3, 30); System.out.println("원 a : "+a); System.out.println("원 b : "+b); if(a.equals(b)) System.out.println("같은 원"); else System.out.println("서로 다른 원"); } } */ /* 패키지 여러개 만드는 건 우선 넘기기 import java.util.*; class Calc { private int x, y; public Calc(int x, int y){ this.x=x; this.y=y; } public int sum() { return x+y; } } public class Main { public static void main(String[] args) { } } */ /* 패키지 여러개 만드는 건 우선 넘기기 import java.util.*; class Shape { public void draw() { System.out.println("Shape"); } } class Circle extends Shape { public void draw() { System.out.println("Circle"); } } public class Main { public static void main(String[] args) { Shape sh=new Circle(); sh.draw(); } } */ /* p.385 5 import java.util.Calendar; public class Main { public static void main(String[] args) { Calendar now=Calendar.getInstance(); int hour=now.get(Calendar.HOUR_OF_DAY); int minute=now.get(Calendar.MINUTE); System.out.println("현재 시간은 "+hour+"시 "+minute+"분입니다."); if(4<=hour&&hour<12) System.out.println("Good Morning"); else if(12<=hour&&hour<18) System.out.println("Good Afternoon"); else if(18<=hour&&hour<20) System.out.println("Good Evening"); else System.out.println("Good Night"); } } */ /* p.385 6 1트 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("10초에 가까운 사람이 이기는 게임입니다."); Calendar now=Calendar.getInstance(); int ASsec=now.get(Calendar.SECOND); int AFsec=now.get(Calendar.SECOND); int BSsec=now.get(Calendar.SECOND); int BFsec=now.get(Calendar.SECOND); System.out.println("A 시작 <Enter> 키 >> "); System.out.println("\t현재 초 시간="+ASsec); //int AFset=Calendar.getInstance().get(Calendar.SECOND); String ent1=sc.nextLine(); System.out.println("10초 예상 후 <Enter> 키 >> "); System.out.println("\t현재 초 시간="+AFsec); System.out.println("B 시작 <Enter> 키 >> "); System.out.println("\t현재 초 시간="+BSsec); //int BFset=Calendar.getInstance().get(Calendar.SECOND); String ent2=sc.nextLine(); System.out.println("10초 예상 후 <Enter> 키 >> "); System.out.println("\t현재 초 시간="+BFsec); int a=Math.abs(ASsec-AFsec); int b=Math.abs(BSsec-BFsec); int c=10-a; int d=10-b; if(c>d) System.out.print("A의 결과 "+a+", "+"B의 결과 "+b+", 승자는 B"); else if(c<d) System.out.print("A의 결과 "+a+", "+"B의 결과 "+b+", 승자는 A"); if(c>d) System.out.print("A의 결과 "+a+", "+"B의 결과 "+b+", 비김"); } } */ /* p.385 6 2트 import java.util.*; class Student { private String name; public Student(String name) { this.name=name; } public String getName() { return name; } } public class Main { public static void main(String[] args) { Student [] s=new Student[2]; System.out.println("10초에 가까운 사람이 이기는 게임입니다."); for(int i=0;i<s.length;i++) { System.out.println(s[i].getName()+" 시작 <Enter> 키 >> "); int Ssec=Calendar.getInstance().get(Calendar.SECOND); System.out.println("현재 초 시간="+Ssec); } } } */ /* p.386 7-1 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(true) { System.out.print(">> "); String a=null; a=sc.nextLine(); if(a.equals("그만")) { System.out.print("종료합니다..."); break; } StringTokenizer s=new StringTokenizer(a, " "); int n=s.countTokens(); System.out.println("어절 개수는 "+n); } } } */ /* p.386 7-2 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(true) { System.out.print(">> "); String a=null; a=sc.nextLine(); if(a.equals("그만")) { System.out.print("종료합니다..."); break; } String [] token=a.split(" "); System.out.println("어절 개수는 "+token.length); } } } */ /* p.386 8 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("문자열을 입력하세요."); String a=null; a=sc.nextLine(); for(int i=0;i<a.length();i++) { System.out.println(a.substring(i+1)+a.substring(0, i+1)); } } } */ /* p.317 5 import java.util.*; class Point { private int x, y; public Point(int x, int y) { this.x=x; this.y=y; } public int getX() { return x; } public int getY() { return y; } protected void move(int x, int y) { this.x=x; this.y=y; } } class ColorPoint extends Point { private String color; public ColorPoint(int x, int y, String color) { super(x, y); this.color=color; } public void setXY(int x, int y) { move(x, y); } public void setColor(String color) { this.color=color; } public String toString() { return color+"색의 ("+getX()+", "+getY()+")의 점"; } } public class Main { public static void main(String[] args) { ColorPoint cp=new ColorPoint(5, 5, "YELLOW"); cp.setXY(10, 20); cp.setColor("RED"); String str = cp.toString(); System.out.println(str + "입니다."); } } */ /* import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(true) { System.out.println("철수[가위(1), 바위(2), 보(3), 끝내기(4) >> "); int key=sc.nextInt(); if(key==1) { Math.random(); } else if(key==4) { System.out.print("종료합니다..."); break; } } } } */
0
0
3
yubinkong
2021년 8월 24일
In 소스 코드 제출
/* 6-1 import java.util.*; class Point { private int x, y; public Point(int x, int y) { this.x=x; this.y=y; } } public class Main { public static void print(Object obj) { System.out.println(obj.getClass().getName()); System.out.println(obj.hashCode()); System.out.println(obj.toString()); System.out.println(obj); } public static void main(String[] args) { Point p=new Point(2, 3); print(p); } } */ /* 6-2 import java.util.*; class Point { int x, y; public Point(int x, int y) { this.x=x; this.y=y; } public String toString() { return "Point("+x+", "+y+")"; } } public class Main { public static void main(String[] args) { Point p=new Point(2, 3); System.out.println(p.toString()); System.out.println(p); System.out.println(p+"입니다."); } } */ /* 6-3 import java.util.*; class Point { int x, y; public Point(int x, int y) { this.x=x; this.y=y; } public boolean equals(Object obj) { Point p=(Point)obj; if(x==p.x&&y==p.y) return true; else return false; } } public class Main { public static void main(String[] args) { Point a=new Point(2, 3); Point b=new Point(2, 3); Point c=new Point(3, 4); if(a==b) System.out.println("a==b"); if(a.equals(b)) System.out.println("a is equal to b"); if(a.equals(c)) System.out.println("a is equal to c"); } } */ /* 6-4 import java.util.*; class Rect { int width, height; public Rect(int width, int height) { this.width=width; this.height=height; } public boolean equals(Object obj) { Rect p=(Rect)obj; if(width*height==p.width*p.height) return true; else return false; } } public class Main { public static void main(String[] args) { Rect a=new Rect(2, 3); Rect b=new Rect(3, 2); Rect c=new Rect(3, 4); if(a.equals(b)) System.out.println("a is equal to b"); if(a.equals(c)) System.out.println("b is equal to c"); if(b.equals(c)) System.out.println("b is equal to c"); } } */ /* 6-5 import java.util.*; public class Main { public static void main(String[] args) { System.out.println(Character.toLowerCase('A')); char c1='4', c2='F'; if(Character.isDigit(c1)) System.out.println(c1+"는 숫자"); if(Character.isAlphabetic(c2)) System.out.println(c2+"는 영문자"); System.out.println(Integer.parseInt("-123")); System.out.println(Integer.toHexString(28)); System.out.println(Integer.toBinaryString(28)); System.out.println(Integer.bitCount(28)); Double d=Double.valueOf(3.14); System.out.println(d.toString()); System.out.println(Double.parseDouble("3.14")); boolean b=(4>3); System.out.println(Boolean.toString(b)); System.out.println(Boolean.parseBoolean("false")); } } */ /* 6-6 import java.util.*; public class Main { public static void main(String[] args) { int n=10; Integer intObject=n; System.out.println("intObject = "+intObject); int m=intObject+10; System.out.println("m = "+m); } } */ /* 6-7 import java.util.*; public class Main { public static void main(String[] args) { String a=new String(" C#"); String b=new String(",C++ "); System.out.println(a+"의 길이는 "+a.length()); System.out.println(a.contains("#")); a=a.concat(b); System.out.println(a); a=a.trim(); System.out.println(a); a=a.replace("C#", "JAVA"); System.out.println(a); String s[]=a.split(","); for(int i=0;i<s.length;i++) System.out.println("분리된 문자열"+i+": "+s[i]); a=a.substring(5); System.out.println(a); char c=a.charAt(2); System.out.println(c); } } */ /* 6-8 import java.util.*; public class Main { public static void main(String[] args) { StringBuffer sb=new StringBuffer("This"); sb.append(" is pencil"); System.out.println(sb); sb.insert(7, " my"); System.out.println(sb); sb.replace(8, 10, "your"); System.out.println(sb); sb.delete(8, 13); System.out.println(sb); sb.setLength(4); System.out.println(sb); } } */ /* 6-9 import java.util.StringTokenizer; public class Main { public static void main(String[] args) { StringTokenizer st=new StringTokenizer("홍길동/장화/홍련/콩쥐/팥쥐", "/"); while(st.hasMoreTokens()) System.out.println(st.nextToken()); } } */ /* 6-10 import java.util.*; public class Main { public static void main(String[] args) { System.out.println(Math.PI); System.out.println(Math.ceil(3.5)); System.out.println(Math.floor(3.5)); System.out.println(Math.sqrt(9)); System.out.println(Math.exp(2)); System.out.println(Math.round(3.14)); System.out.print("이번주 행운의 번호는 "); for(int i=0;i<5;i++) System.out.print((int)(Math.random()*45+1)+" "); } } */ /* 7-1 import java.util.Vector; public class Main { public static void main(String[] args) { Vector<Integer> v=new Vector<Integer>(); v.add(5); v.add(4); v.add(-1); v.add(2, 100); System.out.println("벡터 내의 요소 객체 수 : "+v.size()); System.out.println("벡터의 현재 용량 : "+v.capacity()); for(int i=0;i<v.size();i++) { int n=v.get(i); System.out.println(n); } int sum=0; for(int i=0;i<v.size();i++) { int n=v.elementAt(i); sum+=n; } System.out.println("벡터에 있는 정수 합 : "+sum); } } */ /* 7-2 import java.util.*; class Point { private int x, y; public Point(int x, int y) { this.x=x; this.y=y; } public String toString( ) { return "("+x+", "+y+")"; } } public class Main { public static void main(String[] args) { Vector<Point> v=new Vector<Point>(); v.add(new Point(2, 3)); v.add(new Point(-5, 20)); v.add(new Point(30, -8)); v.remove(1); for(int i=0;i<v.size();i++) { Point p=v.get(i); System.out.println(p); } } } */ /* 7-5 import java.util.*; public class Main { public static void main(String[] args) { HashMap<String, String> dic=new HashMap<String, String>(); dic.put("baby", "아기"); dic.put("love", "사랑"); dic.put("apple", "사과"); Scanner sc=new Scanner(System.in); while(true) { System.out.print("찾고 싶은 단어는? "); String eng=sc.next(); if(eng.equals("exit")) { System.out.println("종료합니다..."); break; } String kor=dic.get(eng); if(kor==null) System.out.println(eng+"는 없는 단어입니다."); else System.out.println(kor); } sc.close(); } } */ /* 7-9 import java.util.*; class GStack<T> { int tos; Object[] stck; public GStack() { tos=0; stck=new Object[10]; } public void push(T item) { if(tos==10) return; stck[tos]=item; tos++; } public T pop() { if(tos==0) return null; tos--; return (T)stck[tos]; } } public class Main { public static void main(String[] args) { GStack<String> stringStack=new GStack<String>(); stringStack.push("seoul"); stringStack.push("busan"); stringStack.push("LA"); for(int n=0;n<3;n++) { System.out.println(stringStack.pop()); } GStack<Integer> intStack=new GStack<Integer>(); intStack.push(1); intStack.push(3); intStack.push(5); for(int n=0;n<3;n++) System.out.println(intStack.pop()); } } */ /* 그전에 했던 5장 상속 1번 import java.util.*; class TV { private int size; public TV(int size) { this.size=size; } protected int getSize() { return size; } } public class Main { public static main(String[] args) { ColorTV myTV=new ColorTV(32, 1024); myTV.printProperty(); } } */ import java.util.*; abstract class Converter { abstract protected double convert(double src); abstract protected String getSrcString(); abstract protected String getDestString(); protected double ratio; public void run() { Scanner sc=new Scanner(System.in); System.out.println(getSrcString()+"을 "+getDestString()+"로 바꿉니다."); System.out.print(getSrcString()+"을 입력하세요 >> "); double val=sc.nextDouble(); double res=convert(val); System.out.println("변환 결과 : "+res+getDestString()+"입니다."); sc.close(); } } public class Main { public static void main(String[] args) { Won2Dollar toDollar=new Won2Dollar(1200); toDollar.run(); } }
0
0
4
yubinkong
2021년 8월 18일
In 소스 코드 제출
/* 5-1 import java.util.*; class Point { private int x, y; public void set(int x, int y) { this.x=x; this.y=y; } public void showPoint() { System.out.println("("+x+", "+y+")"); } } class ColorPoint extends Point { private String color; public void setColor(String color) { this.color=color; } public void showColorPoint() { System.out.print(color); showPoint(); } } public class Main { public static void main(String[] args) { Point p=new Point(); p.set(1, 2); p.showPoint(); ColorPoint cp=new ColorPoint(); cp.set(3, 4); cp.setColor("red"); cp.showColorPoint(); } } */ /* 5-2 import java.util.*; class Person { private int weight; int age; protected int height; public String name; public void setWeight(int Weight) { this.weight=weight; } public int getWeight() { return weight; } } class Student extends Person { public void set() { age=30; name="홍길동"; height=175; setWeight(99); } } public class Main { public static void main(String[] args) { Student s=new Student(); s.set(); } } */ import java.util.*; class TV { private int size; public TV(int size) { this.size=size; } protected int getSize() { return size; } } class ColorTV extends TV { public void printProperty(int s, int c) { System.out.println(); } } public class Main { public static void main(String[] args) { ColorTV myTV=new ColorTV(32, 1024); myTV.printProperty(); } }
0
0
4

yubinkong

더보기
bottom of page