C/C++の宿題片付けます 126代目 at TECH
[2ch|▼Menu]
357:307の間違い
09/05/27 19:14:21
>>307(9255) Vector勉強になった。 それとついでに>>324(9269) >>(9271) N-Queenを解くプログラム
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <time.h>
using namespace std;
struct student {
  string name;
  int score;
};
bool operator<(const student& x, const student& y) {
  return x.score < y.score;
}
int main(void) {
  int i;
  char buf[50];
  student s, t;
  vector<student> vecStudent;
vector<student>::iterator theIterator;
  srand((unsigned)time(0));
  for(i=0; i<20; i++) {
    sprintf(buf, "名前.%02d.名前", i+1); s.name = buf; s.score = rand() % 101;
    vecStudent.push_back(s);
  }
for (theIterator = vecStudent.begin(); theIterator != vecStudent.end(); theIterator++)
    cout << theIterator->name << ":" << theIterator->score << endl;
  cout<<endl; sort(vecStudent.begin(), vecStudent.end());
  for(i=0; i<20; i++)
    t = vecStudent[i], cout<<t.name<<":"<<t.score<<endl;
  return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

5337日前に更新/150 KB
担当:undef