C/C++の宿題を片付けます 58代目
■ このスレッドは過去ログ倉庫に格納されています
0106デフォルトの名無しさん
2006/01/18(水) 23:23:12[2] 問題文(含コード&リンク):
list<int> 型の要素全ての和を求める関数 int sumlist(list<int>&) を定義して下さい.
#include <iostream>
#include <list>
using namespace std;
int main(){
list<int> lst;
for(int i=0 ; i < 10 ; i++)lst.push_back(i);
cout << "size =" << lst.size() << endl;
for(list<int>::iterator it = lst.begin(); it != lst.end() ; ++it)
cout << *it << ' ';
cout << endl;
for(list<int>::iterator it = lst.begin(); it != lst.end() ;){
if((*it) % 3 == 0){
it = lst.erase(it);
}
else {
++it; } }
for(list<int>::iterator it = lst.begin(); it != lst.end() ; ++it)
cout << *it << ' ';
cout << endl;
return 0;}
[3] 環境
[3.1] OS: XP
[3.2] コンパイラ名とバージョン: マイクロソフトビジュアルスタジオ
[3.3] 言語: C++
[4] 期限: 1月23日
[5] その他の制限:
■ このスレッドは過去ログ倉庫に格納されています