本文主要是介绍CF#284 (Div. 2) B.(暴力),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/contest/499/problem/B
解题思路:
开一个is变量记录每组单词最后应该输出哪个。最后每次把原来的数组暴力扫一遍即可。
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;const int maxn = 1000001;struct node
{string a , b;int is;
}k[maxn];
string ans[maxn];int check(string a , string b)
{int lena = a.length();int lenb = b.length();if(lena > lenb)return 2;else if(lena < lenb)return 1;elsereturn 1;
}int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);int n , m;while(cin >> n >> m){for(int i = 0 ; i < m ; i ++){cin >> k[i].a >> k[i].b;k[i].is = check(k[i].a , k[i].b);}for(int i = 0 ; i < n ; i ++){cin >> ans[i];for(int j = 0 ; j < m ; j ++){if(k[j].a == ans[i] || k[j].b == ans[i]){if(k[j].is == 1)ans[i] = k[j].a;elseans[i] = k[j].b;}}}for(int i = 0 ; i < n - 1 ; i ++)cout << ans[i] << " ";cout << ans[n-1] << endl;}
}
这篇关于CF#284 (Div. 2) B.(暴力)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!