#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
vector<int> v1(10,0);
for(int i = 0;i < 10;++i){
cin>>v1[i];
}
for(auto beg = v1.begin();beg != v1.end() - 1;beg++){
cout<<*beg+*(beg+1)<<" ";
}
return 0;
}
上面这道题要注意v1.end()并不是指向最后一个元素,而是指向最后那个元素的后面那个元素,所以for循环里要用v1.end()-1
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<unsigned> scores(11,0);
unsigned grade;
while(cin>>grade){
if(grade <= 100)
++*(scores.begin() + grade/10);
}
for(auto counter : scores)
cout<<counter<<" ";
return 0;
}