VioletaBabel

화학자의 문장 (99점) 본문

알고리즘문제들/codeground
화학자의 문장 (99점)
Beabletoet 2017. 6. 16. 23:33

#include<cstdio>

#include<cstring>

#include<string>

#include<set>

#include<iostream>

#include<algorithm>

using namespace std;

bool check(string in, set<string> c);

int main(int argc, char** argv)

{

int T, test_case;

string chemical[114] = {

"h", "he", "li", "be", "b", "c", "n", "o", "f", "ne",

"na", "mg", "al", "si", "p", "s", "cl", "ar", "k", "ca",

"sc", "ti", "v", "cr", "mn", "fe", "co", "ni", "cu", "zn",

"ga", "ge", "as", "se", "br", "kr", "rb", "sr", "y", "zr",

"nb", "mo", "tc", "ru", "rh", "pd", "ag", "cd", "in", "sn",

"sb", "te", "i", "xe", "cs", "ba", "hf", "ta", "w", "re",

"os", "ir", "pt", "au", "hg", "tl", "pb", "bi", "po", "at",

"rn", "fr", "ra", "rf", "db", "sg", "bh", "hs", "mt", "ds",

"rg", "cn", "fl", "lv", "la", "ce", "pr", "nd", "pm", "sm",

"eu", "gd", "tb", "dy", "ho", "er", "tm", "yb", "lu", "ac",

"th", "pa", "u", "np", "pu", "am", "cm", "bk", "cf", "es",

"fm", "md", "no", "lr" };

set<string> c;

for (int i = 0; i < 114; ++i)

c.insert(chemical[i]);

setbuf(stdout, NULL);

scanf("%d", &T);

for (test_case = 0; test_case < T; test_case++)

{

string in;

cin >> in;

printf("Case #%d\n", test_case + 1);

(check(in, c)) ? printf("YES\n") : printf("NO\n");

}

return 0;

}

bool check(string in, set<string> c)

{

int len = in.length();

bool *one = new bool[len], *two = new bool[len], a = 1;

fill_n(&one[0], len, 0);

fill_n(&two[0], len, 0);

for (int i = 0; i < len; ++i)

{

if (c.count(in.substr(i, 1)))

one[i] = 1;

if (i != len - 1)

if (c.count(in.substr(i, 2)))

{

two[i] = 1;

two[i + 1] = 1;

}

}

for (int i = 0; i < len; ++i)

if (one[i] == 0 && two[i] == 0)

{

a = 0;

break;

}

delete[] one, two;

return a;

}


==============99.595점임. 뭔가 거슬림 빡침.

'알고리즘문제들 > codeground' 카테고리의 다른 글

개구리 뛰기  (0) 2017.06.17
체스판 위의 길 (실패)  (0) 2017.06.17
블럭 없애기 (실패)  (0) 2017.06.16
미궁 속의 방  (0) 2017.06.16
다트 게임  (0) 2017.06.16
Comments