U E D R , A S I H C RSS

새싹교실/2012/AClass/5회차

곽길문

1.koistudy
112-113
#include<stdio.h>

int main()
{
int r,e,c;

scanf("%d %d %d",&r,&e,&c);

if(r< e-c){
printf("advertise\n");
}else if(r>e-c){
printf("do not advertise\n");
}else if(r==e-c){
printf("does not matter\n");
}
}


#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
double x1,x2;
scanf("%d %d %d", &a,&b,&c);
x1=(-b+sqrt(b*b-(4*a*c)))/(2*a);
x2=(-b-sqrt(b*b-(4*a*c)))/(2*a);

if(x1==x2){
printf("%g ",x1);
}else if(x1 !=x2){
if(x1>x2)
printf("%g %g",x1,x2);
else if(x1

printf("%g %g",x2,x1);
}

return 0;
}

/*115-
#include<stdio.h>

int main(){
int a;
int sum=0;

scanf("%d",&a);

for(;a >1;a--){
sum+=a;
}


printf("%d",sum+1);
return 0;

}
*/

/* 116-
#include<stdio.h>
int main(){
int n,k;
int i=1;
int sum=0;

scanf("%d %d",&n,&k);

while(i<=n){
if(i%k ==0){
sum+=i;
}
i++;
}

printf("%d",sum);
return 0;
}
*/

/*119-
#include<stdio.h>
int main(){
int a;
int count=0;

scanf("%d",&a);

a= a*2-1;


for(count=0;count < a;count++)
printf("*");
return 0;
}
*/

/*120-
#include<stdio.h>
int main(){
int a;
int i,j;

scanf("%d",&a);

for(i=0;i
for(j=0;j
printf("*");
}

printf("\n");
}

return 0;

}
*/

/*121-
#include<stdio.h>
int main(){
int a;
int i,j;

scanf("%d",&a);

for(i=0;i
for(j=0;j
printf("*");
}

printf("\n");
}

for(i=0;i
for(j=a;j>i+1;j--){
printf("*");
}

printf("\n");
}

return 0;

}
*/


122-#include<stdio.h>

int main()
{

int a;
int i,j;

scanf("%d",&a);
if(a!=1){
for(i=1;i<10;i++){
printf("%d*%d=%d\n",a,i,a*i);
}

}else if(a==1){
for(i=1;i<10;i++){
for(j=2;j<10;j++){
printf("%d*%d=%d ",j,i,j*i);
}
printf("\n");
}
}
return 0;

}
2.Swap함수 작성

--#include<stdio.h>

void swap(int *a,int *b);
int main()
{
char x='A',y='B';
printf("x= %c y=%c\n",x,y);

swap(&x,&y);
printf("x=%c ,y=%c\n",x,y);
return 0;


}
void swap(int *a,int *b)
{

int temp;
temp=*a;
*a=*b;
*b=temp;

}

  1. 3,4,6,7,9,3,2를 입력으로 넣은 후 2,3,9,7,6,4,3순서로 출력하는 프로그램을 작성해보세요.(스택)
#include<stdio.h>
#define MaxSize 7
int stackMaxSize;

int sp=0;
int push(int);
int pop(int *);

int main(){

int n=0;
push(3);
push(4);
push(6);
push(7);
push(9);
push(3);
push(2);
if (push(40) == -1)
{

printf("Stack Overflow\n");

}
pop(&n);
printf("pop : %d\n",n);

pop(&n);
printf("pop : %d\n",n);

pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);

if(pop(&n) == -1)
{
printf("Stack Underflow\n");

}
return 0;
}


int push(int n)
{
if(sp<MaxSize)
{
stacksp=n;
sp++;
return 0;

}else
{
return -1; // 가튀�득姨�찾£을≫때納�overflow
}

}

int pop(int *n)
{
if(sp>0) //값튕�이I 있O을≫ 때納�
{
sp--;
*n=stacksp;
return 0;

}else
{
return -1; //비촱었�을≫ 때納� underflow

}
}


4.BinarySearch가 무엇인지 찾아보고, 가능하면 한번 구현해보도록 합시다.(가능하면!)

-이진 탐색은 제어검색에서 가장 대표적인 방법으로 한번 비교동작이 끝난 후 그 결과를 이용하여 다음에 비교할 대상을 선택하는 방법으로 검색한다. 주어진 파일들을 일정한 순서대로 배열된 상태에서 원하는 값을 검색하는 방법이다.

•아래와 같은 출력이 나오는 프로그램을 어떻게하면 짤 수 있는지 생각해서 써보도록 합시다. 그 방법이 확실하다고 생각되면 짜보아도 좋아요

1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

- 5X5배열을 우선 배정, 1,2,3,4,5를 우선 0행에 출력, 마지막 4행에 도달했을 때 4열 출력, 마지막 4행에 도달했을 때 4행 출력, 0행에 도달했을 때 (전체 행수-1)만큼 출력 ... 반복....


한송이

1.koistudy113번 못풀었음

2.Swap함수 작성
#include<stdio.h>
int swap(int *a,int *b);

int main(void){
	int a = 4;
	int b = 6;
	
	swap(&a,&b);
	printf("%d %d",a,b);
	

	return 0;
}

int swap(int *a,int *b){
	int temp;

	temp= *a;
	*a = *b;
	*b = temp;

	return swap(a,b);
}

4.BinarySearch가 무엇인지 찾아보고, 가능하면 한번 구현해보도록 합시다.(가능하면!)
  • 이진검색은 제어검색에서 가장 대표적인 방법이다.
  • 한번 비교 동작이 끝난 후, 그 결과를 이용하여 다음에 비교할 대상(K
    (K는 찾고자 하는 값, Ki는 중간 자료 값들)
  • 주어진 파일들은 일정한 순서대로 배열된 상태에서 원하는 값을 검색하는 방법이다
  • 이진탐색은 이미 데이터들이 정렬 된 상태 + 중복값이 없을 때 가능한 탐색방법이다.
    만약 데이터들이 정렬이 되 있지만 중복값이 존재하면 중복된 값 중 하나만 찾으며,
    정렬이 되있지 않은 데이터들을 이진탐색을 하면 데이터를 찾지 못한다.

    나머지는 진짜 너무 어려움

도상희


복습과제

1.KoiStudy 112~113,115~122 - 문제 많은데 별찍기같은건 한거라서 몇개 할거 없을거에요.
- 113번 빼고 모두 완료.

2.Swap함수 작성
#include <stdio.h>
void swap(int*, int*);
int main(){
	int a=5;
	int b=2;
	printf("a:%d b:%d\n",a,b);
	swap(&a,&b);
	printf("a:%d b:%d\n",a,b);

	return 0;
}
void swap(int* x, int* y){
	int temp;
	temp=*x;
	*x=*y;
	*y=temp;
}

3.3,4,6,7,9,3,2를 입력으로 넣은 후 2,3,9,7,6,4,3순서로 출력하는 프로그램을 작성해보세요.(스택)
#include <stdio.h>
int main(){
	int arr[7]={0,};
	int n,i;

	for(i=0 ; i<7 ; i++){
		scanf("%d",&n);
		arr[i]=n;
	}

	for(i=6 ; i>=0 ; i--){
		printf("%d  ",arr[i]);
	}
	printf("\n");

	return 0;
}


4.BinarySearch가 무엇인지 찾아보고, 가능하면 한번 구현해보도록 합시다.(가능하면!)
아래와 같은 출력이 나오는 프로그램을 어떻게하면 짤 수 있는지 생각해서 써보도록 합시다. 그 방법이 확실하다고 생각되면 짜보아도 좋아요
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

6.LinkedList를 구현할 수 있는 구조체를 하나 만들고, 그 구조체를 이용해 linkedlist하나를 만들어봅시다.
#include <stdio.h>
#include <stdlib.h>

struct Linkedlist{
	int data;
	struct Linkedlist *next;
};

int main(){
	struct Linkedlist *p1 = (struct Linkedlist*)malloc(sizeof(struct Linkedlist));
	struct Linkedlist *p2 = (struct Linkedlist*)malloc(sizeof(struct Linkedlist));
	p1->data = 10;
	p1->next = p2;
	p2->data = 20;
	p2->next = NULL;
	printf("%d\n",p1->next->data);
	
	return 0;
}


7.동적할당을 이용해 list가 몇개 연결되어있는 구조를 만들어봅시다. list->next->next = 동적할당;
#include <stdio.h>
#include <stdlib.h>

struct Linkedlist{
	int data;
	struct Linkedlist *next;
};

int main(){
	struct Linkedlist *p1 = (struct Linkedlist*)malloc(sizeof(struct Linkedlist));
	p1->next=(struct Linkedlist*)malloc(sizeof(struct Linkedlist));
	p1->next->next=(struct Linkedlist*)malloc(sizeof(struct Linkedlist));
	p1->data=10;
	p1->next->data=20;
	p1->next->next->data=30;

	printf("%d\n",p1->data);
	printf("%d\n",p1->next->data);
	printf("%d\n",p1->next->next->data);
	return 0;
}


8.LinkedList를 만들고, 리스트 data에 4,5,3,7,12,24,2,9가 들어가도록 해봅시다.


예습과제

1.Koistudy163
2.163번 문제를 풀고, 그 문제를 어떻게 접근하였는지 말해봅시다.
#include <stdio.h>
int main(){
	char arr[9];
	int n;
	int i;
	scanf("%d",&n);
	scanf("%s",arr);
	for(i=0 ; i<8 ; i++){
		printf("%c",arr[i]+n);
	}
	printf("\n");

	return 0;
}


3.문자열이 대칭인경우 Palindrome, 아닌경우 Not Palindrome을 출력하는 프로그램을 작성해봅시다.
level, racecar, deed는 palindrome, sadfds는 not Palindrome





황혜림

1.6.1.1 복습과제

1.KoiStudy 112~113,115~122 - 문제 많은데 별찍기같은건 한거라서 몇개 할거 없을거에요.


2.Swap함수 작성
#include <stdio.h>
void Swap(int *a, int *b);
int main()
{
int a=4;
int b=9;

printf("변경 전 : a = %d, b = %d\n",a,b);
Swap(&a,&b);
printf("변경 후 : a = %d, b = %d\n",a,b);

return 0;
}

void Swap(int *a,int *b)
{
int temp;

temp=*a;
*a=*b;
*b=temp;
}
3.3,4,6,7,9,3,2를 입력으로 넣은 후 2,3,9,7,6,4,3순서로 출력하는 프로그램을 작성해보세요.(스택)
#include <stdio.h>

int main()
{
int arr[7];
int sp=0;

while(1)
{
if(sp==7)
{
break;
}
scanf("%d",&arr[sp++]);

}

while(1)
{
if(sp==0)
break;
printf("%d ",arr[--sp]);
}

return 0;
}
4.BinarySearch가 무엇인지 찾아보고, 가능하면 한번 구현해보도록 합시다.(가능하면!)
이진 탐색.
- 정렬된 데이터 집합에서 사용할 수 있는 고속 탐색 알고리즘 입니다.
- 이진 탐색이라는 이름은 알고리즘의 핵심이 탐색 범위를 1/2씩 줄여나가는 방식에 있기 때문에 붙여진 것입니다.

수행 과정.
- 1. 데이터 집합의 중앙에 있는 요소를 고릅니다.
- 2. 중앙 요소의 값과 찾고자 하는 목표 값을 비교합니다.
- 3. 목표 값이 중앙 요소의 값보다 작다면 중앙을 기준으로 데이터 집합의 왼편에 대해 새 로 검색을 수행하고 크다면 오른편에 대해 이진 탐색을 새로이 수행합니다.
- 4. 탐색의 완료 될 때까지 1 ~ 3번 과정을 반복합니다.

#include <stdio.h>

int binary (int arr[], int low, int high, int key);

int main()
{
int arr[10]={1,3,13,15,16,17,22,26,32,50};
int key;
int search;

scanf("%d",&key);

search=binary(arr,0,9,key);
if(search==1)
printf("Find");
else
printf("Not Find");

return 0;
}

int binary(int arr[], int low, int high, int key)
{
int mid;

while(low<=high)
{
mid=(low+high)/2;

if(arr[mid]==key)
return 1;
else if(arr[mid]>key)
high=mid-1;
else
low=mid+1;
}
return 0;
}
5.아래와 같은 출력이 나오는 프로그램을 어떻게하면 짤 수 있는지 생각해서 써보도록 합시다. 그 방법이 확실하다고 생각되면 짜보아도 좋아요
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

6.LinkedList를 구현할 수 있는 구조체를 하나 만들고, 그 구조체를 이용해 linkedlist하나를 만들어봅시다.

#include <stdio.h>

struct node{
int data;
struct node *next;
};
int main()
{
struct node *list=(struct node*)malloc(sizeof(struct node));

return 0;
}

7.동적할당을 이용해 list가 몇개 연결되어있는 구조를 만들어봅시다. list->next->next = 동적할당;
#include <stdio.h>

struct node{
int data;
struct node *next;
};

int main()
{
struct node *list=(struct node*)malloc(sizeof(struct node));
list->next=(struct node*)malloc(sizeof(struct node));
list->next->next=(struct node*)malloc(sizeof(struct node));
return 0;
}

8.LinkedList를 만들고, 리스트 data에 4,5,3,7,12,24,2,9가 들어가도록 해봅시다.

1.6.1.2 예습과제

1.Koistudy163
2.163번 문제를 풀고, 그 문제를 어떻게 접근하였는지 말해봅시다.
#include <stdio.h>

int main()
{
int key;
char code[100];
int i=0;

scanf("%d",&key);
scanf("%s",code);

while(code[i]!='\0')
{
printf("%c",key+code[i]);
i++;
}
return 0;
}

3.문자열이 대칭인경우 Palindrome, 아닌경우 Not Palindrome을 출력하는 프로그램을 작성해봅시다.
level, racecar, deed는 palindrome, sadfds는 not Palindrome
#include <stdio.h>
#include <string.h> // strlen() 함수 사용하기 위해

int main()
{
char arr[100];
int i=0;
int len;
scanf("%s",arr);
len=strlen(arr);  ///문자열의 길이 알려 줌

for(i=0;i<len;i++)
{
if(arr[i]!=arr[len-i-1])
{
printf("Not Palindrome\n");
return 0;;
}

}
printf("Palindrome\n");
return 0;

}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:45
Processing time 0.0422 sec