Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<unordered_map>
- #define long long long
- #define nln '\n'
- using namespace std;
- long n;
- int main()
- {
- cin >> n;
- string st1 = "" , st2 = "";
- bool fal = 0;
- unordered_map<string, bool > dic;
- long loc = 0;
- for (long i = 1; i <= n; ++i)
- {
- cin >> st2;
- if (st1 == "")
- {
- dic[st2] = 1;
- st1 = st2;
- continue;
- }
- if (st2[0] != st1[st1.size()-1] || dic[st2])
- {
- loc = i;
- fal = 1;
- break;
- }
- dic[st2] = 1;
- st1 = st2;
- }
- if (!fal)
- cout << "YES" << nln;
- else
- {
- cout << "NO" << nln;
- cout << loc << nln;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment