Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //
  2. //This is HW9 done by Kyul Lee(Koi).
  3. //
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <vector>
  9. #include <cstdlib>
  10.  
  11. using namespace std;
  12.  
  13. vector<int> vec;
  14.  
  15. void Swap (int &i, int &j) {
  16. int temp=i;
  17. i=j;
  18. j=temp;
  19. }
  20.  
  21. void BubbleSort (vector<int> &students , int size) {
  22. for (int i=0; i<size; i++) {
  23. for (int j=0; j<size; j++) {
  24. if (students[i] > students[j+1])
  25. Swap(students[j], students[j+1]);
  26. }
  27. for (int i=0; i<size; i++) {
  28. cout << students[i] << " ";
  29. }
  30. cout << endl;
  31. }
  32. }
  33. int main () {
  34. ifstream fin;
  35. string file;
  36. string words;
  37. int i=1;
  38. int students;
  39. int numStudent;
  40. cout << "Enter the file: ";
  41. cin >> file;
  42. fin.open(file);
  43. while (fin >> words) {
  44. if (i == 1) {
  45. numStudent = atoi(words.data());
  46. }
  47. else if (i > 1) {
  48. students = atoi(words.data());
  49. vec.push_back(students);
  50. cout << "i==" << words << endl;
  51. }
  52. i++;
  53. }
  54. BubbleSort (vec, numStudent);
  55. for (int i=0; i<numStudent; i++) {
  56. cout << "i==" << vec[i] << endl;
  57. }
  58. int score;
  59. int count=1;
  60. for (int i=0; i<numStudent; i++) {
  61. score = vec[i];
  62. if (score == vec[i+1]) {
  63. count++;
  64. }
  65. else {
  66. cout << "There was " << count << " score of " << score << endl;
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement