プログラマー-株価

1685 ワード

#include <string>
#include <vector>
 
using namespace std;

int compare(int a, int b)
{
    if (a<=b)
        return 1;
    else
        return 0;
}
 
vector<int> solution(vector<int> prices) {
    vector<int> answer;
    for(int i=0; i < prices.size()-1; i++)
    {
      //  if(i == prices.size()){answer.push_back(0); return answer;}
        int Count = 0;
        for(int j = i+1; j<prices.size() ; j++ )
        {
            Count = Count + compare(prices[i],prices[j]);
            if(0==compare(prices[i], prices[j])){ Count++; break;}
        }
        answer.push_back(Count);
    }
     answer.push_back(0);
    return answer;
}

2つ目のリングはドアの例で、5番が入っているのでできない問題です.
初期に比べてif forゲートの操作能力は多く発展した.
最近社内で大きなプロジェクトを担当し、久しぶりにアルゴリズムの解答をアップロードしました.(言い訳)
2番目のfor文では、compare関数をしなくてもいいので、使ってもいいですが、他の人の解答で何度も使ったスタイルです.