티스토리 뷰

  • 공백없애기
#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[101], b[101];
	int i, p=0;
	gets(a);	// scanf로는 공백을 포함한 문자를 모두 읽을 수 없음 
	for(i=0; a[i]!='\0'; i++){
		if(a[i]!= ' '){
			if(a[i]>=65 && a[i]<=90){
				b[p++]=a[i]+32;
			} else {
				b[p++]=a[i];
			}
		}
	}
	b[p]='\0';
	printf("%s\n", b);
	
	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[101];
	int i, cnt=0;
	scanf("%s", &a);
	for(i=0; a[i]!='\0'; i++){
		if(a[i]=='(') cnt++;
		else if(a[i]==')') cnt--;
		if(cnt<0) break;
	}
	if(cnt==0) printf("YES\n"); 
	else printf("NO\n");
	return 0;
}

'algorithm' 카테고리의 다른 글

[c++] 자릿수의 합  (0) 2020.11.29
[c++] 모두의 약수  (0) 2020.11.28
나이차이, 나이계산, 숫자만추출  (0) 2020.11.26
자연수의 합, 진약수의 합  (0) 2020.11.25
[Algorithm] 순환(recursion) 알고리즘(예제)  (0) 2020.05.30
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/09   »
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
글 보관함