1. 程式人生 > >今日頭條筆試題

今日頭條筆試題

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, x, num;
    while(cin >> n >> x)
    {
        vector<int> house;
        for (int i=0; i<n; i++){
            cin >> num;
            house.push_back(num);
        }
        num = 0
; while (house[x-1]){ ++num; --house[x-1]; --x; if(x == 0) x = n; } house[x-1] = num; for(int i=0; i<n; ++i) cout << house[i] << " "; cout << endl; } return 0
; }