View Code of Problem 97

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string str[1005], ans[1005];
int n, idx = 0;
string tmp;

void findAndPrint(string ss, int pos) {
	for(int i = 0; i < n; i++) {
		if(i != pos && str[i] == ss) ans[idx++] = str[i] + ".exe";
	}
}

int main() {
	cin >> n;
	while(n != 0) {
		for(int i = 0; i < n; i++) cin >> str[i];
//		cout << "*********" << endl;
		for(int i = 0; i < n; i++) {
			if(str[i].find(".exe") != -1) {
//				string zz = str[i];
				int pos = str[i].find(".exe");
//				str[i].erase(pos);
				string tmp = str[i];
				tmp.erase(pos, 4);
//				cout << "*" << tmp << "*" << endl;
				findAndPrint(tmp, i);
			}
		}
		sort(ans, ans + idx);
		for(int i = 0; i < idx; i++) {
			cout << ans[i] << endl;
		}
		cin >> n;
		idx = 0;
	}
}

Double click to view unformatted code.


Back to problem 97