Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created July 26, 2019 14:06
Show Gist options
  • Save surinoel/e4896056139b63e14e60a33a707d19c8 to your computer and use it in GitHub Desktop.
Save surinoel/e4896056139b63e14e60a33a707d19c8 to your computer and use it in GitHub Desktop.
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
string s;
cin >> s;
istringstream sin(s);
vector<int> a;
string num;
while (getline(sin, num, ',')) {
a.push_back(stoi(num));
}
for (int i = 0; i < m; i++) {
vector<int> b;
for (int i = 0; i < a.size() - 1; i++) {
b.push_back(a[i + 1] - a[i]);
}
a = b;
}
for (int i = 0; i < a.size(); i++) {
if (i != a.size() - 1) cout << a[i] << ',';
else cout << a[i];
}
cout << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment