[백준] #8892 팰린드롬

kkily·2022년 3월 20일
0

[알고리즘]

목록 보기
82/102

문제

무려 15번의 제출끝에 맞았다 ㅋㅋㅋㅋ
"\n"을 출력을 안해서 계속 틀렸던 건데 다른 게 틀린줄 알고 고치다가 산으로 갔다.
령언니가 코드를 봐줘서 결국 맞을 수 있었다! 허무하지만 기쁘다!

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    int t,check=0;
    int num;
    cin>>t;
    string s,add1,temp1;
    vector<string> str;

    for(int i=0;i<t;i++){
        cin>>num;
        str.clear();
        check=0;
       
        for(int j=0;j<num;j++){
            cin>>s;
            str.push_back(s);
        }
         
        

        for(int p=0;p<num;p++){
            if(check==1){
                break;
            }
            for(int l=0;l<num;l++){
               
                if(p==l){
                    continue;
                }

                add1=str[p]+str[l];
                temp1=add1;
                reverse(add1.begin(),add1.end());
                if(add1==temp1){
                    cout<<temp1<<"\n";
                    check=1;
                    break;
                }

                
            }
            

        }
        if(check==0)
            cout<<0<<"\n";
    }
}
profile
낄리의 개발 블로그╰(*°▽°*)╯

0개의 댓글