A1077 Kuchiguse (20 分)

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int minLen = 256;

int main(int argc, char** argv) {
    
    
	int n;
	int ans = 0;
	string s[110];
	cin >> n;
	cin.get();
	
	for(int i = 0; i < n; i++){
    
    
		getline(cin, s[i]);
		int len = s[i].length();
		if(len < minLen) minLen = len;
		reverse(s[i].begin(), s[i].end());
	}
	
	for(int i = 0; i < minLen; i++){
    
    
		char c = s[0][i];
		bool same = true;
		for(int j = 1; j < n; j++){
    
    
			if(c != s[j][i]){
    
    
				same = false;
				break;
			}
		}
		if(same == true){
    
    
			ans++;
		}else{
    
    
			break;
		}
	}
	
	if(ans){
    
    
		for(int i = ans - 1; i >= 0; i--){
    
    
			cout << s[0][i];
		}
	}else{
    
    
		cout << "nai";
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/alovelypeach/article/details/114267999