[HIHO1385]A Simple Job(模拟)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[HIHO1385]A Simple Job(模拟)相关的知识,希望对你有一定的参考价值。

题目链接:http://hihocoder.com/problemset/problem/1385

题意:给出几段话,问哪个连续两个由空格隔开的单词对出现最多。

模拟啊模拟,只会写模拟。

  1 #include <algorithm>
  2 #include <iostream>
  3 #include <iomanip>
  4 #include <cstring>
  5 #include <climits>
  6 #include <complex>
  7 #include <fstream>
  8 #include <cassert>
  9 #include <cstdio>
 10 #include <bitset>
 11 #include <vector>
 12 #include <deque>
 13 #include <queue>
 14 #include <stack>
 15 #include <ctime>
 16 #include <set>
 17 #include <map>
 18 #include <cmath>
 19 using namespace std;
 20 #define fr first
 21 #define sc second
 22 #define cl clear
 23 #define BUG puts("here!!!")
 24 #define W(a) while(a--)
 25 #define pb(a) push_back(a)
 26 #define Rint(a) scanf("%d", &a)
 27 #define Rll(a) scanf("%I64d", &a)
 28 #define Rs(a) scanf("%s", a)
 29 #define Cin(a) cin >> a
 30 #define FRead() freopen("in", "r", stdin)
 31 #define FWrite() freopen("out", "w", stdout)
 32 #define Rep(i, len) for(int i = 0; i < (len); i++)
 33 #define For(i, a, len) for(int i = (a); i < (len); i++)
 34 #define Cls(a) memset((a), 0, sizeof(a))
 35 #define Clr(a, x) memset((a), (x), sizeof(a))
 36 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
 37 #define lrt rt << 1
 38 #define rrt rt << 1 | 1
 39 #define pi 3.14159265359
 40 #define RT return
 41 #define lowbit(x) x & (-x)
 42 #define onecnt(x) __builtin_popcount(x)
 43 typedef long long LL;
 44 typedef long double LD;
 45 typedef unsigned long long ULL;
 46 typedef pair<int, int> pii;
 47 typedef pair<string, int> psi;
 48 typedef pair<LL, LL> pll;
 49 typedef map<string, int> msi;
 50 typedef vector<int> vi;
 51 typedef vector<LL> vl;
 52 typedef vector<vl> vvl;
 53 typedef vector<bool> vb;
 54 
 55 const int maxn = 550;
 56 typedef struct Node {
 57     string s;
 58     bool end;
 59     Node() {}
 60     Node(string ss, bool e) : s(ss), end(e) {}
 61 }Node;
 62 
 63 vector<Node> words;
 64 map<pair<string, string>, int> ret;
 65 char tmp[maxn];
 66 char qq[maxn];
 67 
 68 void gao() {
 69     int pre = 0, pos = 0;
 70     bool flag = 0;
 71     while(tmp[pos]) {
 72         if(tmp[pos] ==  ) {
 73             pos++;
 74             continue;
 75         }
 76         if(tmp[pos] == , || tmp[pos] == .) {
 77             words[words.size()-1].end = 1;
 78             pos++;
 79             continue;
 80         }
 81         pre = pos;
 82         while(tmp[pos] !=   && tmp[pos] != , && tmp[pos] != . && tmp[pos]) pos++;
 83         Cls(qq);
 84         for(int i = pre; i < pos; i++) {
 85             qq[i-pre] = tmp[i];
 86         }
 87         words.push_back(Node(qq, 0));
 88     }
 89 }
 90 
 91 signed main() {
 92     // FRead();
 93     int _ = 1;
 94     while(gets(tmp)) {
 95         ret.clear();
 96         words.clear();
 97         gao();
 98         words[words.size()-1].end = 1;
 99         while(gets(tmp) && strcmp(tmp, "####") != 0) {
100             gao();
101             words[words.size()-1].end = 1;
102         }
103         Rep(i, words.size()-1) {
104             if(words[i].end) continue;
105             ret[make_pair(words[i].s, words[i+1].s)]++;
106         }
107         map<pair<string, string>, int>::iterator it;
108         pair<string, string> wtf;
109         int tmp = 0;
110         for(it = ret.begin(); it != ret.end(); it++) {
111             if(tmp < it->second) {
112                 tmp = it->second;
113                 wtf = it->first;
114             }
115         }
116         cout << wtf.first << " " <<wtf.second <<":" << tmp << endl;
117     }
118     RT 0;
119 }

 

以上是关于[HIHO1385]A Simple Job(模拟)的主要内容,如果未能解决你的问题,请参考以下文章

hihoCoder 1385 : A Simple Job(简单工作)

ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job

[HIHO1039]字符消除(字符串,枚举,模拟)

CA Simple Job

vijos- P1385盗窃-月之眼 (水题 + python)

hiho一下157