パターンを保持しながらリスト要素の可能な限り多くの合計を数えるスクリプトがあります:higher-lower-higher-lower -higherなどC++エラー: '(std :: list <int>)(int&)'への呼び出しに一致しません
#include <algorithm>
#include <stdio.h>
#include <list>
using namespace std;
int main() {
int n=0;
bool g = false;
int d = 1000000;
list<int> a(d,0);
int b;
for (int x=0; x<n; x++) { //load the list elements
scanf("%d", &b);
a.push_back(b);
}
for (int i=0; a(n) == a(n+1); i++) {
a.remove(n+1); //this is to remove any (consecutive) duplicates
}
if (a(n) > a(n+1)) {
g = false;
} else {
g = true;
}
while (n+1 < d) {
if (g) {
if (!(a(n) < a(n+1))) {
a.remove(n+1);
continue;
} else {
n = n+1;
g = !g;
continue;
}
} else {
if (!(a(n) > a(n+1))) {
a.remove(n+1);
} else {
n = n+1;
g = !g;
continue;
}
}
}
long long sum = 0 ;
for (int i = 0 ; i < a.count(); i++) {
sum += a(i);
}
printf("%lld ", sum);
return 0;
}
私は、リストの要素を比較しようとしていますどこただし、コンパイルの試みでそれはどこでもno match for call to '(std::list<int>) (int&)'
をスローします。
私は間違っていますか?
cmon people - なぜdownvote。 OPは完全なコードを提供しますが、少し不明瞭なエラーメッセージ(ただし、それを提供します)。さらに何を求めることができるか – pm100