1077 Kuchiguse (20 point(s))

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string t, res;
int n;
int main() {
	scanf("%d%*c", &n);
	getline(cin, res);
	reverse(res.begin(), res.end());
	for(int i = 0; i < n - 1; ++i) {
		getline(cin, t);
		reverse(t.begin(), t.end());
		int cnt = res.length() < t.length() ? res.length() : t.length();
		for(int i = cnt; i >= 0; --i) if(res.substr(0, i) == t.substr(0, i)) {
			res = res.substr(0, i);
			break;
		}
	} 
	reverse(res.begin(), res.end());
	if(res.length()) cout << res << '\n';
	else cout << "nai" << '\n';
	return 0;
}

 

相关文章:

  • 2021-11-17
  • 2021-12-18
  • 2021-12-19
  • 2021-10-28
  • 2021-06-29
  • 2022-01-23
  • 2021-11-30
  • 2021-10-22
猜你喜欢
  • 2022-01-05
  • 2021-12-07
  • 2021-09-23
  • 2021-04-20
  • 2021-07-11
  • 2021-09-08
  • 2022-12-23
相关资源
相似解决方案