Skip to content

Instantly share code, notes, and snippets.

@izanbf1803
Last active April 24, 2017 15:51
Show Gist options
  • Save izanbf1803/93e5a1b76af3512b957099b77b5b2a52 to your computer and use it in GitHub Desktop.
Save izanbf1803/93e5a1b76af3512b957099b77b5b2a52 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
using namespace std;
const int abc_size = 26;
int main()
{
vector<int> lval(abc_size);
lval[0] = 1;
for (int i = 1; i < abc_size; i++) {
lval[i] = lval[i-1] + i + 1;
}
vector<string> lines;
string line;
while (cin >> line) {
lines.push_back(line);
}
vector<vector<int>> grid(lines.size(), vector<int>(lines[0].size()));
grid[0][0] = lval[lines[0][0] - 'A'];
for (int i = 1; i < grid.size(); i++) {
grid[i][0] = lval[lines[i][0] - 'A'] + grid[i-1][0];
}
for (int i = 1; i < grid[0].size(); i++) {
grid[0][i] = lval[lines[0][i] - 'A'] + grid[0][i-1];
}
for (int i = 1; i < grid.size(); i++) {
for (int j = 1; j < grid[0].size(); j++) {
grid[i][j] = lval[lines[i][j] - 'A'] + grid[i-1][j] + grid[i][j-1] - grid[i-1][j-1];
}
}
for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid[0].size(); j++) {
if (j > 0) cout << " ";
cout << grid[i][j];
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment