코드 Chapter 1
                                            
 3791 단어  알고리즘 경연 입문 경전(제2판)
                    
알고리즘 경연 QQ군: 210838572, 함께 진보합시다!  
예제 코드  
1-1 원통체의 표면적
  // 1-1
#include 
#include 
int main()
{
	const double pi = acos(-1.0); // ¦Ð 
	double r, h, s1, s2, s;
	scanf("%lf%lf", &r, &h); // C99
	s1 = pi*r*r;
	s2 = 2*pi*r*h;
	s = s1*2 + s2;
	printf("Ares = %.3f
", s);
	return 0;
}  
  
1-2 세 자리 반전
  // 1-2
#include 
int main()
{
	int num;
	scanf("%d", &num);
	printf("%d%d%d
", num%10, num/10%10, num/100);
	return 0;
}
 
  
1-3 교환 변수
  // 1-3
#include 
int main()
{
	int a, b, t;
	scanf("%d%d", &a, &b);
	t = a;
	a = b;
	b = t;
	printf("%d %d
", a, b);
	return 0;
}
 
  
1-4 닭과 토끼 한 바구니
  // 1-4
#include 
int main()
{
	int x, y, m, n;
	scanf("%d%d", &n, &m);
	y = (m-2*n)/2;
	x = n-y;
	if(m % 2 == 1 || x < 0 || y < 0) // ¼¦ÍþùΪÕûÊý£¬²¢ÇÒ¶¼´óÓÚ0 
	{
		printf("No Answer
");
	}
	else
	{
		printf("%d %d
", x, y);
	}
	return 0;
}
 
  
1-5 정수 정렬
  // 1-5
#include 
void swap(int &x, int &y);
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a > b){swap(a, b);}
	if(a > c){swap(a, c);}
	if(b > c){swap(b, c);}
	printf("%d %d %d
", a, b, c); 
	return 0; 
}
void swap(int &x, int &y)
{
	int t;
	t = x;
	x = y;
	y = t;
	return;
}
 
  
연습 문제 코드  
t1-1 평균(average)
  // t1-1
#include 
int main()
{
	double x, y, z, res;
	scanf("%lf%lf%lf", &x, &y, &z);
	res = (x+y+z)/3;
	printf("%.3f
", res);
	return 0;
}
 
  
t1-2 온도
  // t1-2
#include 
int main()
{
	double f, c;
	scanf("%lf", &f);
	c = 5*(f-32)/9;
	printf("%.3f
", c);
	return 0;
}
 
  
t1-3 연속 및 (sum)
  // t1-3
#include 
int main()
{
	double n, res;
	scanf("%lf", &n);
	res = n*(n+1)/2;
	printf("%.3f", res);
	return 0;
}
 
  
t1-4 정현과 여현 (sin과cos)
  // t1-4
#include 
#include 
int main()
{
	const double pi = acos(-1.0);
	double n, s, c;
	scanf("%lf", &n);
	n = n/180*pi;
	s = sin(n);
	c = cos(n);
	printf("%f %f", s, c);
	return 0;
}
  
  
t1-5 할인(discount)
  // t1-5
#include 
int main()
{
	const double PRICE = 95;
	const double sale = 0.85;
	double n, cost;
	scanf("%lf", &n);
	cost = PRICE*n;
	if(cost >= 300)
	{
		printf("%.2f
", cost*sale);
	}
	else
	{
		printf("%.2f
", cost);
	}
	return 0;
}
 
  
t1-6 삼각형(triangle)
  // t1-6
#include 
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(!(a+b > c)) {printf("not a triangle
"); return 0;}
	if(!(a+c > b)) {printf("not a triangle
"); return 0;}
	if(!(b+c > a)) {printf("not a triangle
"); return 0;}
	if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
	{
		printf("yes
");
	}
	else
	{
		printf("no
");
	}
	return 0;
}
 
  
t1-7년(year)
  // t1-7
#include 
int main()
{
	int year;
	scanf("%d", &year);
	if(year%4 == 0 && year%100 != 0)
	{
		printf("yes
");
	}
	else
	{
		printf("no
"); 
	} 
	return 0;
}
 
                
                    
        
    
    
    
    
    
                
                
                
                
                
                
                    
                        
                            
                            
                                
                                    
                                    이 내용에 흥미가 있습니까?
                                
                            
                            
                            
                            현재 기사가 여러분의 문제를 해결하지 못하는 경우  AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
                            
                                
                                UVa 10976 Fractions Again?!(분수 분할)
                            
                            제목 링크: UVA 10976
제목:
정수 k를 입력하고 모든 정수 x>y를 찾으면 1/k=1/x+1/y가 됩니다.
CODE:...
                            
                            
                            
                            
                            텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
                            
                        
                    
                
                
                
            
1-1 원통체의 표면적
// 1-1
#include 
#include 
int main()
{
	const double pi = acos(-1.0); // ¦Ð 
	double r, h, s1, s2, s;
	scanf("%lf%lf", &r, &h); // C99
	s1 = pi*r*r;
	s2 = 2*pi*r*h;
	s = s1*2 + s2;
	printf("Ares = %.3f
", s);
	return 0;
}  1-2 세 자리 반전
// 1-2
#include 
int main()
{
	int num;
	scanf("%d", &num);
	printf("%d%d%d
", num%10, num/10%10, num/100);
	return 0;
}
 1-3 교환 변수
// 1-3
#include 
int main()
{
	int a, b, t;
	scanf("%d%d", &a, &b);
	t = a;
	a = b;
	b = t;
	printf("%d %d
", a, b);
	return 0;
}
 1-4 닭과 토끼 한 바구니
// 1-4
#include 
int main()
{
	int x, y, m, n;
	scanf("%d%d", &n, &m);
	y = (m-2*n)/2;
	x = n-y;
	if(m % 2 == 1 || x < 0 || y < 0) // ¼¦ÍþùΪÕûÊý£¬²¢ÇÒ¶¼´óÓÚ0 
	{
		printf("No Answer
");
	}
	else
	{
		printf("%d %d
", x, y);
	}
	return 0;
}
 1-5 정수 정렬
// 1-5
#include 
void swap(int &x, int &y);
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a > b){swap(a, b);}
	if(a > c){swap(a, c);}
	if(b > c){swap(b, c);}
	printf("%d %d %d
", a, b, c); 
	return 0; 
}
void swap(int &x, int &y)
{
	int t;
	t = x;
	x = y;
	y = t;
	return;
}
 연습 문제 코드  
t1-1 평균(average)
  // t1-1
#include 
int main()
{
	double x, y, z, res;
	scanf("%lf%lf%lf", &x, &y, &z);
	res = (x+y+z)/3;
	printf("%.3f
", res);
	return 0;
}
 
  
t1-2 온도
  // t1-2
#include 
int main()
{
	double f, c;
	scanf("%lf", &f);
	c = 5*(f-32)/9;
	printf("%.3f
", c);
	return 0;
}
 
  
t1-3 연속 및 (sum)
  // t1-3
#include 
int main()
{
	double n, res;
	scanf("%lf", &n);
	res = n*(n+1)/2;
	printf("%.3f", res);
	return 0;
}
 
  
t1-4 정현과 여현 (sin과cos)
  // t1-4
#include 
#include 
int main()
{
	const double pi = acos(-1.0);
	double n, s, c;
	scanf("%lf", &n);
	n = n/180*pi;
	s = sin(n);
	c = cos(n);
	printf("%f %f", s, c);
	return 0;
}
  
  
t1-5 할인(discount)
  // t1-5
#include 
int main()
{
	const double PRICE = 95;
	const double sale = 0.85;
	double n, cost;
	scanf("%lf", &n);
	cost = PRICE*n;
	if(cost >= 300)
	{
		printf("%.2f
", cost*sale);
	}
	else
	{
		printf("%.2f
", cost);
	}
	return 0;
}
 
  
t1-6 삼각형(triangle)
  // t1-6
#include 
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(!(a+b > c)) {printf("not a triangle
"); return 0;}
	if(!(a+c > b)) {printf("not a triangle
"); return 0;}
	if(!(b+c > a)) {printf("not a triangle
"); return 0;}
	if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
	{
		printf("yes
");
	}
	else
	{
		printf("no
");
	}
	return 0;
}
 
  
t1-7년(year)
  // t1-7
#include 
int main()
{
	int year;
	scanf("%d", &year);
	if(year%4 == 0 && year%100 != 0)
	{
		printf("yes
");
	}
	else
	{
		printf("no
"); 
	} 
	return 0;
}
 
                
                    
        
    
    
    
    
    
                
                
                
                
                
                
                    
                        
                            
                            
                                
                                    
                                    이 내용에 흥미가 있습니까?
                                
                            
                            
                            
                            현재 기사가 여러분의 문제를 해결하지 못하는 경우  AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
                            
                                
                                UVa 10976 Fractions Again?!(분수 분할)
                            
                            제목 링크: UVA 10976
제목:
정수 k를 입력하고 모든 정수 x>y를 찾으면 1/k=1/x+1/y가 됩니다.
CODE:...
                            
                            
                            
                            
                            텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
                            
                        
                    
                
                
                
            
// t1-1
#include 
int main()
{
	double x, y, z, res;
	scanf("%lf%lf%lf", &x, &y, &z);
	res = (x+y+z)/3;
	printf("%.3f
", res);
	return 0;
}
 // t1-2
#include 
int main()
{
	double f, c;
	scanf("%lf", &f);
	c = 5*(f-32)/9;
	printf("%.3f
", c);
	return 0;
}
 // t1-3
#include 
int main()
{
	double n, res;
	scanf("%lf", &n);
	res = n*(n+1)/2;
	printf("%.3f", res);
	return 0;
}
 // t1-4
#include 
#include 
int main()
{
	const double pi = acos(-1.0);
	double n, s, c;
	scanf("%lf", &n);
	n = n/180*pi;
	s = sin(n);
	c = cos(n);
	printf("%f %f", s, c);
	return 0;
}
  // t1-5
#include 
int main()
{
	const double PRICE = 95;
	const double sale = 0.85;
	double n, cost;
	scanf("%lf", &n);
	cost = PRICE*n;
	if(cost >= 300)
	{
		printf("%.2f
", cost*sale);
	}
	else
	{
		printf("%.2f
", cost);
	}
	return 0;
}
 // t1-6
#include 
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(!(a+b > c)) {printf("not a triangle
"); return 0;}
	if(!(a+c > b)) {printf("not a triangle
"); return 0;}
	if(!(b+c > a)) {printf("not a triangle
"); return 0;}
	if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
	{
		printf("yes
");
	}
	else
	{
		printf("no
");
	}
	return 0;
}
 // t1-7
#include 
int main()
{
	int year;
	scanf("%d", &year);
	if(year%4 == 0 && year%100 != 0)
	{
		printf("yes
");
	}
	else
	{
		printf("no
"); 
	} 
	return 0;
}
 이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
UVa 10976 Fractions Again?!(분수 분할)제목 링크: UVA 10976 제목: 정수 k를 입력하고 모든 정수 x>y를 찾으면 1/k=1/x+1/y가 됩니다. CODE:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.