zoukankan      html  css  js  c++  java
  • 题解【洛谷P2264】情书

    题面

    看到每一单词在同一句话中出现多次感动值不叠加,一眼想到 ( ext{set})

    首先将词汇列表中的单词存储起来,我用的是 ( ext{set})

    对于每一个句子的单词,我们可以先判断它是否是词汇列表中的单词,然后将它加入一个 ( ext{set}) 中,如果扫描到句号就将答案加上 ( ext{set}) 的大小,然后清空 ( ext{set})

    #include <bits/stdc++.h>
    #define DEBUG fprintf(stderr, "Passing [%s] line %d
    ", __FUNCTION__, __LINE__)
    #define itn int
    #define gI gi
    
    using namespace std;
    
    typedef long long LL;
    typedef pair <int, int> PII;
    typedef pair <int, PII> PIII;
    
    inline int gi()
    {
    	int f = 1, x = 0; char c = getchar();
    	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return f * x;
    }
    
    inline LL gl()
    {
    	LL f = 1, x = 0; char c = getchar();
    	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return f * x;
    }
    
    int n, ans;
    string xsl, pp;
    set <string> td, kk; 
    
    int main()
    {
    	//freopen("1.in", "r", stdin);
    	//freopen(".out", "w", stdout);
    	n = gi();
    	for (int i = 1; i <= n; i+=1)
    	{
    		cin >> xsl;
    		int len = xsl.size();
    		for (int j = 0; j < len; j+=1)
    		{
    			if (xsl[j] >= 'A' && xsl[j] <= 'Z') xsl[j] = xsl[j] - 'A' + 'a';
    		}
    		td.insert(xsl);
    	}
    	char c = getchar();
    	xsl = "";
    	while (~scanf("%c", &c))
    	{
    		//puts("!");
    		if (c == '
    ') break;
    		if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
    		if (c >= 'a' && c <= 'z') xsl = xsl + c;
    		else 
    		{
    			if (xsl != "") 
    			{
    				if (td.find(xsl) != td.end()) kk.insert(xsl);
    				xsl = "";
    			}
    			if (c == '.') 
    			{
    				ans += kk.size(), kk.clear();
    			}
    		}
    	}
    	printf("%d
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    八月份总结+项目总结
    缓存图片技术
    7月份总结
    【转】JavaScript 事件顺序:冒泡和捕获
    【转】UTF16和UTF8什么区别?
    【转】javascript和html中unicode编码和字符转义的详解
    【笔记】javascript权威指南-第六章-对象
    Delphi 中的MD5实现方法《转》
    DELPHI 代码块集合
    Delphi Access 表中查询日期时间提示出错的问题《转》
  • 原文地址:https://www.cnblogs.com/xsl19/p/12310052.html
Copyright © 2011-2022 走看看