跳过正文
  1. Posts/

uva 409 - Excuses, Excuses!

·2 分钟

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=350 题意:给出k个key word,e个借口…找出包含key word最多的借口,即为最坏的借口。匹配补区分大小写&&同一个key word算多次。 思路:需要注意的是因为不区分大小写,需要都转化成大写或者小写。。但是输出的时候要输出原始的。。所以要另外存一份。

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年01月22日 星期五 17时58分02秒
  4File Name :code/uva/409.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33string str[50];
 34int k,e;
 35int num[50];
 36set<string>se;
 37
 38struct node
 39{
 40    string exc;
 41    string ori;
 42    int num;
 43    bool operator<(node b)const
 44    {
 45	return num>b.num;
 46    }
 47}ex[50];
 48
 49int main()
 50{
 51	#ifndef  ONLINE_JUDGE
 52	freopen("code/in.txt","r",stdin);
 53  #endif
 54	int cas = 0 ;
 55	while (scanf("%d %d",&k,&e)!=EOF)
 56	{
 57	    se.clear();
 58	    ms(num,0);
 59	    printf("Excuse Set #%d\n",++cas);
 60
 61	    for ( int i = 0 ; i < k ; i++)
 62	    {
 63		cin>>str[i];
 64		int len = str[i].length();
 65		for ( int j = 0 ; j < len ;j++)
 66		{
 67		    str[i][j] = tolower(str[i][j]);
 68		}
 69		se.insert(str[i]);
 70	    }
 71	    getchar();
 72//	    for ( int i = 0 ; i < k ;i++) cout<<"str[i]:"<<str[i]<<endl;
 73	    for ( int i = 0 ; i < e ; i++)
 74	    {
 75		getline(cin,ex[i].exc);
 76		ex[i].ori=ex[i].exc;
 77		int len = ex[i].exc.length();
 78		for ( int j = 0 ; j < len ; j++)
 79		{
 80		    ex[i].exc[j] = tolower(ex[i].exc[j]);
 81		    if (ex[i].exc[j]<'a'||ex[i].exc[j]>'z')
 82			ex[i].exc[j]=' ';  //把非字母部分都转化成空格.
 83		}
 84	    }
 85
 86//	    for ( int i = 0 ; i < e ; i++) cout<<"exc[i]:"<<ex[i].exc<<endl;
 87
 88	    int ans = -1;
 89
 90	    for ( int i = 0 ; i < e ;i++)
 91	    {
 92		int cnt = 0 ;
 93		string cpy = ex[i].exc;
 94		int pos = 0 ;
 95		while (pos!=-1)
 96		{
 97		    pos = cpy.find(' ');
 98		    string tmp = cpy.substr(0,pos-0);
 99		    if (se.count(tmp)==1) cnt++;
100		    cpy.erase(0,pos+1);
101		    //cout<<i<<"cpy:"<<cpy<<cpy.length()<<endl;
102		}
103
104		ex[i].num=cnt;
105	    }
106//	    for ( int i = 0 ; i < e ; i++) cout<<"num[i]:"<<ex[i].num<<endl;
107	    sort(ex,ex+e);
108	    for ( int i = 0 ; i < e ; i++)
109	    {
110		if (ex[i].num==ex[0].num)
111		{
112		    cout<<ex[i].ori<<endl;
113		}
114	    }
115	    cout<<endl;
116	}
117
118
119  #ifndef ONLINE_JUDGE
120  fclose(stdin);
121  #endif
122    return 0;
123}

相关文章

hdu 5611 || BC #69 div2 1002 Baby Ming and phone number

·2 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=5611 题意:给出n个电话号码(长度为11的字符串),满足特殊条件的价格为a,否则为b.特殊条件为最后5位数字一样,最后5位严格递增或者严格递减,最后8位是一个1980年1月一日到2016年12月31日的合法日期。问最后的价值。

uva 537 Artificial Intelligence?

·2 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=478 题意:给出一段文字。。其中包含了 P,U,I(功率,电压,电流)中的两个。。求第三个。 思路:字符串处理。。第一次用vim复制整段代码。。命令模式下按v,然后光标扫过的区域都会选中,按y就就复制到剪贴板了。。 所以虽然代码写了300行但只有100行是需要写的。。200行复制改下就好== WA了两次。。一次是因为I写成了小写。。另一次是因为多组数据记得初始化多次。

uva 10010 - Where's Waldorf?

·3 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951 题意:给出一个由大小写字母组成的二维maze…给出k个询问。每个询问一个单词。问能否在maze中找到这个单词。不区分大小写。输出开头字母的坐标(从1开始)。如果有多组输出最上面的。如果还有多组,输出最左边的。数据保证至少有一组。 思路:直接找就好了。。。坑的地方是。。。格式。。数据组数之后会有一个空行。然后每两组读入数据之间会有一个空行。。输出的时候每两组数据之间也有一个空行。

uva 401 Palindromes

·2 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 题意:问一个字符串是不是回文串,是不是镜像串。镜像串的意思是。。从镜子里看还一样。。给定了一些存在镜像的字母和数字。。 思路:回文串的判断用c++的string要更容易一些。。直接reverse一下。。判断是否相等就行。。。然后需要注意的是。。如果某个字符补存在镜像那么一定不是镜像串

uva 10420 - List of Conquests

·1 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1361 题意:给n个带空格的字符串,第一个单词是国家,统计每个国家的字符串的个数。 思路:getline函数。。。find函数。。。substr函数。。。map…..