티스토리 뷰

  • 나이차이
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	//freopen("input.txt", "rt", stdin);
	int n, i, a, max=-2147000000, min=2147000000;
	cin>>n;
	
	for(i = 1; i <= n; i++){
		cin>>a;
		if(a>max){
			max=a;
		}
		if(a<min){
			min=a;
		}
	}
	cout<<max-min;
	return 0;
}

 

  • 나이계산
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	//freopen("input.txt", "rt", stdin);
	char a[20];
	int year, age;
	scanf("%s", &a);
	if(a[7]=='1' || a[7]=='2'){
		year = 1900 + ((a[0]-48)*10+(a[1]-48));
	} else {
		year = 2000 + ((a[0]-48)*10+(a[1]-48)); 
	}
	
	age = 2019 - year + 1;
	printf("%d ", age);
	if(a[7]=='1' || a[7]=='3'){
		printf("M\n");
	} else {
		printf("W\n");
	}	
	return 0;
}

 

  • 숫자만 추출
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	//freopen("input.txt", "rt", stdin);
	char a[100];
	int res=0, cnt=0, i;
	scanf("%s", &a);
	for(i=0; a[i]!='\0'; i++){
		if(a[i]>=48 && a[i]<=57){
			res = res*10+(a[i]-48);
		}
	}
	printf("%d\n", res);
	for(i=1; i<=res; i++){
		if(res%i==0){
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함