Untitled
unknown
c_cpp
a year ago
960 B
4
Indexable
Never
#include<bits/stdc++.h> using namespace std; int main() { int n, upperBound = -1; bool breakNow = false; vector<string> stringList; cin >> n; for(int i = 0; i < n; ++i) { string str; cin >> str; stringList.push_back(str); } for(int i = 0; ; ++i) { char currentLetter; if(i >= stringList[0].size()) { upperBound = i - 1; break; } else { currentLetter = stringList[0][i]; } for(int j = 1; j < stringList.size(); ++j) { if(i >= stringList[j].size() || stringList[j][i] != currentLetter) { breakNow = true; upperBound = i - 1; } } if(breakNow) break; } if(upperBound == -1) { cout << "ans : " } else { cout << "ans : " << stringList[0].substr(0, upperBound + 1); } return 0; }