Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题,sqrt用int做参数竟然CE,苯地都直接过的(這種題就是欠STL)

Posted by KatrineYang at 2016-08-23 03:40:16 on Problem 1119 and last updated at 2016-08-23 03:42:36
#include <iostream>
#include <map>
#include <string>
#include <cmath>
#include <stdio.h>
using namespace std;

string getZM(string s){
	int len = s.length();
	string res = "";
	for(int i = 0; i < len; i++){
		if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= '0' && s[i] <= '9')) res += s[i];
		else if(s[i] >= 'A' && s[i] <= 'Z') res += (char)(s[i]-'A'+'a');
	}
	return res;
}

int main() {
	map<string, int> searchTerms;
	string s;
	while(1){
		cin >> s;
		if(s == "----------") break;
		s = getZM(s);
		if(s.length() == 0) continue;
		if(searchTerms.find(s) != searchTerms.end()){
			searchTerms[s] ++;
		}
		else{
			searchTerms.insert(pair<string, int>(s, 1));
		}
	}
	while(1){
		bool firstLine = 1;
		map<string, int> fileTerms;
		while(1){
			cin >> s;
			if(s == "----------"){
				if(firstLine) return 0;
				else break;
			}
			firstLine = 0;
			s = getZM(s);
			if(s.length() == 0) continue;
			if(fileTerms.find(s) != fileTerms.end()){
				fileTerms[s]++;
			}
			else{
				fileTerms.insert(pair<string, int>(s, 1));
			}
		}
		double ans = 0;
		for(map<string, int>::iterator it = searchTerms.begin(); it != searchTerms.end(); it++){
			if(fileTerms.find(it->first) == fileTerms.end()) continue;
			ans += sqrt(it->second * fileTerms[it->first] + 0.0);
		}
		printf("%.2lf\n", ans);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator