链接链接2
代码1:
const int N = 510;
char g[N][N];
int n, m;
int dp[N][N];
#include <iostream>
#include <algorithm>
using namespace std;
int main() {cin >> n >> m;for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++) {cin >> g[i][j];int t = 0;if (g[i][j] == 'l')t = 4;else if (g[i][j] == 'o')t = 3;else if (g[i][j] == 'v')t = 2;else if (g[i][j] == 'e')t = 1;dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + t;}}cout << dp[n][m] << endl;
}
第一次写的时候把g数组定义为了 int g[N][N];
代码2:
#include <iostream>
#include <string>
using namespace std;int main() {string s, res;cin >> s;int n = s.size();for (int i = 0; i < n; i++) {res += s[i];if ((n - i - 1) % 3 == 0 && (i != n - 1)) {res += ',';}}cout << res << endl;return 0;
}
这是一道模拟题,题目中给出一个整数(比如4957121),我们可以作为string读入。res作为结果.