Thief of Wealth
Published 2019. 3. 30. 18:28
11328 Stfry 개발/알고리즘

Strfry 성공

영어   

시간 제한메모리 제한제출정답맞은 사람정답 비율

2 초 256 MB 227 127 117 55.981%

문제

In the C programming language, strings are not a native data type. In fact, they are just an array of characters, with a sentinel NULL value used to denote the end of the string. Since working with strings is a very important thing to do in programming languages, the C standard library has several very useful functions for string manipulation: among them are strcpystrcmpstrtolstrtokstrlen, and strcat.

However, there is one function that not many know about, and even fewer use it: the strfry function. strfry takes an input string and randomly swaps a random number of characters.

Given two strings, determine if it is possible that the second string is the first string, strfried.

입력

The input begins with a number 0 < N < 1001, the number of test cases.

Each test case consists of a single line containing two strings of lowercase English characters, separated by a single space; these are the two strings in question. Each string is at most 1000 characters long.

출력

Output one line for each test case, containing either "Impossible" or "Possible" (without quotes).

 

C++의 STL인 string을 사용했는데 erase의 사용법을 잘못알아서 자꾸 틀렸다

 

string1.erase(삭제할인덱스, 삭제할인덱스로부터 얼마나 삭제할것인가?); 임을 꼭 기억하자

 

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <list>
using namespace std;

int main(){


	freopen("input.txt","r",stdin);

	ios::sync_with_stdio(false);
	cin.tie(0);

	string str;
	string str2;

	int T;
	cin>>T;
	
	for(int t=0; t<T; ++t){
		cin>>str;
		cin>>str2;
		if( str.length() != str2.length() ){
			cout<<"Impossible\n";
		}else {

			for(int j=0; j<str.length() && !str2.empty(); ++j){

				int index = str2.find(str.at(j));
				if(index+1){
					str2.erase(index,1);
				}
			
			}

			if(str2.empty()){
				cout<<"Possible\n";
			}else {
				cout<<"Impossible\n";
			}

		}
		
		
	}
	return 0;
}

'개발 > 알고리즘' 카테고리의 다른 글

1919 애너그램 만들기  (0) 2019.03.31
5398 키로거  (0) 2019.03.31
1406 에디터  (0) 2019.03.30
1182 부분수열의 합  (0) 2019.03.24
1018 체스판 다시 칠하기  (0) 2019.03.24
profile on loading

Loading...