HDU 4329 Contest 3

果然换个编译器就过了。总的来说,不难,不过就是处理一些空格。学习了一个新的类 istringstream可以按空格划分。然后,那条式子要理解。

式子的意义是:

找到一个串,该串在query中是第几个找到/它的实际位置。之和再除以给出的有几个串就是AVEP

#include <iostream>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>

using namespace std;
string str[105];
string sstr[105];

int main(){
	int T,kase=0,n,t1,t2;	double ans,par;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		getchar();
		for(int i=1;i<=n;i++)
		getline(cin,str[i]);
		for(int i=1;i<=n;i++)
		getline(cin,sstr[i]);
		ans=0;
		for(int i=1;i<=n;i++){
			par=0;
			map<string,int>M;
			stringstream sin(str[i]);
			string c;
			t1=t2=0;
			sin>>c;
			while(sin>>c){
				M[c]=1;
				t1++;
			}
			if(t1==0) continue;
			stringstream csin(sstr[i]);
			csin>>c;
			int j=0;
			while(csin>>c){
				t2++;
				if(M.find(c)!=M.end()){
					j++;
					par+=(double)j/t2;
				}
			}
			ans+=(par/t1);
		}
		printf("Case #%d: %.6lf
",++kase,ans/n);
	}
}

  

原文地址:https://www.cnblogs.com/jie-dcai/p/4087433.html