View Code of Problem 97

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while(cin>>n) {
		if(n==0) break;
		string file[n], str;
		string exe[1001],virus[1001];
		int count=0,count2=0;
		for(int i=0; i<n; i++) cin>>file[i];
		//将普通文件与exe文件分开 
		for(int i=0; i<n; i++) {
			str="";
			for(int j=file[i].length()-1; j>=file[i].length()-4; j--) str+=file[i][j];
			if(str=="exe.") {//exe文件 
				str="";
				for(int j=0; j<file[i].length()-4; j++) str+=file[i][j];
				exe[count++]=str;
				file[i]="";
			} 
		}
		for(int i=0; i<count; i++) {
			for(int j=0; j<n; j++) {
				if(file[j]!=""&&exe[i]==file[j]) {//是病毒 
					exe[i]+=".exe";//给病毒加.exe后缀 
					virus[count2++]=exe[i];
				}
			}
		}
		//给病毒排序
		sort(virus,virus+count2);
		for(int i=0; i<count2; i++) cout<<virus[i]<<endl;
	}
} 

Double click to view unformatted code.


Back to problem 97