답안 #578250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578250 2022-06-16T09:17:51 Z Trisanu_Das 고장난 휴대전화기 (COCI14_mobitel) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
bool isSubstring(string s1, string s2)
{
    if (s2.find(s1) != string::npos)
        return true;
    return false;
}

int main(){
  string op ={"2","22","222","3","33","333","4","44","444","5","55","555","6","66","666","7","77","777","7777","8","88","888","9","99", "999","9999"};
  int bev[9];
  for(int i = 0; i < 9 ; i++) cin >> bev[9];
  string s; cin >> s;
  string ans;
  int n = s.size();
  for(int i = 0; i < n - 1; i++){
    ans += op[(int)(s[i] - 'a')];
    if(isSubstring(s[i], s[i + 1])) ans += '#';
  }
  cout << ans << '\n';
}

Compilation message

mobitel.cpp: In function 'int main()':
mobitel.cpp:11:149: error: could not convert '{"2", "22", "222", "3", "33", "333", "4", "44", "444", "5", "55", "555", "6", "66", "666", "7", "77", "777", "7777", "8", "88", "888", "9", "99", "999", "9999"}' from '<brace-enclosed initializer list>' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   11 |   string op ={"2","22","222","3","33","333","4","44","444","5","55","555","6","66","666","7","77","777","7777","8","88","888","9","99", "999","9999"};
      |                                                                                                                                                     ^
      |                                                                                                                                                     |
      |                                                                                                                                                     <brace-enclosed initializer list>
mobitel.cpp:19:34: error: could not convert 's.std::__cxx11::basic_string<char>::operator[](((std::__cxx11::basic_string<char>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   19 |     if(isSubstring(s[i], s[i + 1])) ans += '#';
      |                                  ^
      |                                  |
      |                                  __gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}