Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice bad practice; avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice; avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice; avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

edited body
Source Link
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice ,; avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice , avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice ; avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

added 46 characters in body
Source Link
Barry
  • 18.5k
  • 1
  • 40
  • 92

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice, avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice, avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code.

Include the right things

You're starting with:

#include <bits/stdc++.h>
using namespace std;

The second line is bad practice, avoid it. Typing std:: is not a burden. The former is definitely unacceptable - that's a compiler-specific file that you don't want to be including. Just include the actual headers you need:

#include <iostream>
#include <algorithm>
#include <vector>

Use algorithms and iterators

Rather than writing your own loop to perform a sum, you could use the standard algorithm for this: std::accumulate:

int sum = std::accumulate(v.begin(), v.end(), 0);

Also they wanted you to use iterators to find the median, which would be:

auto median_it = std::next(
 v.begin(),
 std::distance(v.begin(), v.end()) / 2);

Where's the rest?

There's a lot of text in that question that I don't think you addressed in your code. Looks like we need a std::map or something.

Source Link
Barry
  • 18.5k
  • 1
  • 40
  • 92
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /