05-02 21:40
Recent Posts
Recent Comments
관리 메뉴

너와나의 관심사

백준 1343 문자열 처리 문제..(strstr 함수사용 본문

카테고리 없음

백준 1343 문자열 처리 문제..(strstr 함수사용

벤치마킹 2018. 9. 16. 16:41

백준 1343 문제 폴리오미노 (문자열 처리 문제) 


https://www.acmicpc.net/problem/1343

strstr 함수를 사용해서 간단히 푸는 방법 으로 너무 고민 하지 말자 . 그리고 세상에 고수는 많다 


설명

strstr() 함수는 string1에서 string2의 첫 번째 표시를 찾습니다. 함수는 일치 프로세스에서 string2로 끝나는 널 문자(\0)를 무시합니다.

리턴값

strstr() 함수는 string1에서 string2의 첫 번째 표시 시작 위치에 대한 포인터를 리턴합니다. string2가 string1에 나타나지 않으면 strstr() 함수는 NULL을 리턴합니다. string2가 길이가 0인 스트링을 가리키면 strstr() 함수는 string1을 리턴합니다.


#include 
#include  
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define	ABS(a)	 a<0 ?-(a):a	// 절대 값


char in[101];
char buffer[1001][101];
int cnt = 0;



char a[] = "AAAA";
char b[] = "BB";
char x4[] = "XXXX";
char x2[] = "XX";
char s[555];

int main() {

		
	freopen("input.txt", "r", stdin); setbuf(stdout, NULL);
	cin >> s;

	char *p;
	while ((p = strstr(s, x4))){
		strncpy(p, a, 4);
	}

	while ((p = strstr(s, x2))){
		strncpy(p, b, 2);
	}
	bool judge = true;
	for (int i = 0; s[i]; i++){
		if (s[i] == 'X'){
			judge = false;
			break;
		}
	}	

	if (judge){
		cout << s << endl;
	}
	else{
		cout << "-1" << endl;
	}
	
	return 0;


	return 0;
}








Comments