文章目录
- C++
- 总结
本题链接:202109-1 数组推导
本博客给出本题截图:
C++
#include <iostream> using namespace std; const int N = 110; int b[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i ++ ) cin >> b[i]; int suma = b[1], sumi = b[1]; int j = 1; for (int i = 2; i <= n; i ++ ) { if (b[i] == b[j]) suma += b[j]; else { suma += b[i]; sumi += b[i]; j = i; } } cout << suma << endl << sumi << endl; return 0; }
总结
水题,不解释