以下のようにコードを書きます。
(質問は一部のエラーだけなので一番下の質問とエラーを先に見て頂ければよろしいと思います。)
c++
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<char> VC; typedef vector<double> VD; typedef vector<double> VL; typedef vector<string> VS; typedef vector<PLL> VP; typedef vector<ll> VLL; const static int INF = 1000000000; const static int MOD = 1000000007; #define rep(i,n) for (ll i=0; i<(ll)(n); i++) #define repd(i,n) for (ll i=n-1; i>=0; i--) #define rept(i,m,n) for(ll i=m; i<n; i++) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) (x).begin(), (x).end() #define F first #define S second #define PF push_front #define PB push_back #define SORT(V) sort((V).begin(), (V).end()) #define RVERSE(V) reverse((V).begin(), (V).end()) #define paired make_pair #define PRINT(V) for(auto v : (V)) cout << v << " " int main(){ int n; cin>>n; vector<int> s(n); rep(i,n){ cin>>s[i]; } vector<int> time(10); int cnt[10]; rep(i,n){ //0~9までの場合でかかる時間をそれぞれ求めてtimeにpushしていく int t=-1; rep(j,n){ rep(k,10){ if(s[j][k]==i){ cnt[k]++; } } } cout<<cnt<<endl; int time1=-1; rep(j,10){ if(cnt[j]!=0){ time1=j; break; } } int time2=0; rep(j,10){ if(2<=cnt[j]){ time2+=cnt[j]-1; } } t=time1+time2*10; time.push_back(t); } int ans; rep(i,n) ans=min(ans,time[i]); cout<<ans<<endl; }
すると以下のようなエラーが出てきてしまいます。
c++
./Main.cpp: In function ‘int main()’: ./Main.cpp:46:18: error: invalid types ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[ll {aka long long int}]’ for array subscript 46 | if(s[j][k]==i){ | ^
このエラーの意味がよく分かりません。
自分の中では、おそらくs[j][k]とiの型が比較演算子を使うのには不適切な組み合わせをしているのだと思っています。
このエラーはどのようにしたら直せますか?型変換の仕方等の技術がまだまだ不十分なので教えてもらいたいです。
回答よろしくお願いします。m(_ _"m)
まだ回答がついていません
会員登録して回答してみよう