Submission #5445938


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using P = pair<int, int>;

static const string words[] = {"tokyo", "kyoto"};

int main() {
  int T; cin >> T;
  for (int i{}; i < T; ++i) {
    vector<P> vec;
    string S;
    cin >> S;
    for (const auto& word : words) {
      for (size_t pos{}; (pos = S.find(word, pos)) != string::npos; ++pos) {
        // pos += hoge.length() wouldn't allow overlapping occurrences to be found.
        vec.push_back(P{pos, pos + word.length()});
      }
    }
    sort(vec.begin(), vec.end(), [](P l, P r) {
      if (l.second == r.second)
        return l.first > r.first;
      return l.second < r.second;
    });

    int ans{};
    int pos{};
    for (const auto& p : vec) {
      if (pos <= p.first) {
        ++ans;
        pos = p.second;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task A - 東京都
User tatsu
Language C++ (GCC 5.4.1)
Score 0
Code Size 880 Byte
Status CE

Compile Error

./Main.cpp:4:7: error: expected nested-name-specifier before ‘P’
 using P = pair<int, int>;
       ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:10:13: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   for (int i{}; i < T; ++i) {
             ^
./Main.cpp:10:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   for (int i{}; i < T; ++i) {
              ^
./Main.cpp:11:12: error: ‘P’ was not declared in this scope
     vector<P> vec;
            ^
./Main.cpp:11:13: error: template argument 1 is invalid
     vector<P> vec;
             ^
./Main.cpp:11:13: error: template argument 2 is invalid
./Main.cpp:14:22: error: ISO C++ forbids declaration of ‘word’ with no type [-fpermissive]
     for (const auto& word : words) {
                      ^
./Main.cpp:14:29: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
     for (const auto& word : words) {
                             ^
./Main.cpp:15:22: warn...