Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //This is HW9 done by Kyul Lee(Koi).
- //
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <cstdlib>
- using namespace std;
- vector<int> vec;
- void Swap (int &i, int &j) {
- int temp=i;
- i=j;
- j=temp;
- }
- void BubbleSort (vector<int> &students , int size) {
- for (int i=0; i<size; i++) {
- for (int j=0; j<size; j++) {
- if (students[i] > students[j+1])
- Swap(students[j], students[j+1]);
- }
- for (int i=0; i<size; i++) {
- cout << students[i] << " ";
- }
- cout << endl;
- }
- }
- int main () {
- ifstream fin;
- string file;
- string words;
- int i=1;
- int students;
- int numStudent;
- cout << "Enter the file: ";
- cin >> file;
- fin.open(file);
- while (fin >> words) {
- if (i == 1) {
- numStudent = atoi(words.data());
- }
- else if (i > 1) {
- students = atoi(words.data());
- vec.push_back(students);
- cout << "i==" << words << endl;
- }
- i++;
- }
- BubbleSort (vec, numStudent);
- for (int i=0; i<numStudent; i++) {
- cout << "i==" << vec[i] << endl;
- }
- int score;
- int count=1;
- for (int i=0; i<numStudent; i++) {
- score = vec[i];
- if (score == vec[i+1]) {
- count++;
- }
- else {
- cout << "There was " << count << " score of " << score << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement