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.0484 sec