2 条题解

  • 0
    @ 2025-4-10 22:08:28
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 105,M=30, INF = 0x3f3f3f3f, MOD = 1E9 + 7;
    int a[N][M]; // 如果看不懂下面的vector 写法可以使用这个
    void solve() {
        int n, m;
        cin >> n >> m;
       // vector<vector<int> > a(n + 5, vector<int>(m + 5));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                cin >> a[i][j];
        string s;
        cin >> s;
        int ans = 0, x = 0, y = 0;
        for (int i = 1; i < s.size(); i++) {
            if (isalpha(s[i])) {
                y = s[i] - 'A';
            } else if (isdigit(s[i]) || i == s.size() - 1) {
                x = x * 10 + s[i] - '0';
            }
            if (s[i] == '+' || i == s.size() - 1) {
                // 输出调试
                // cout << char(x + 'A') << y << " " << a[x - 1][y] << endl;
                ans += a[x - 1][y];
                x = 0;
            }
        }
        cout << ans << endl;
    }
    int main(int argc, char* argv[]) {
        int t = 1;
        // cin >> t;
        while (t--) {
            solve();
        }
        return 0;
    }
    
    • 0
      @ 2025-4-9 10:36:52
      • 本题是个模拟,在调试中可以输出数据进行验证,这样不容易出错。
      #include <bits/stdc++.h>
      using namespace std;
      typedef long long ll;
      const int N = 105,M=30, INF = 0x3f3f3f3f, MOD = 1E9 + 7;
      //int a[N][M]; // 如果看不懂下面的vector 写法可以使用这个
      void solve() {
          int n, m;
          cin >> n >> m;
          vector<vector<int> > a(n + 5, vector<int>(m + 5));
          for (int i = 0; i < n; i++)
              for (int j = 0; j < m; j++)
                  cin >> a[i][j];
          string s;
          cin >> s;
          int ans = 0, x = 0, y = 0;
          for (int i = 1; i < s.size(); i++) {
              if (isalpha(s[i])) {
                  y = s[i] - 'A';
              } else if (isdigit(s[i]) || i == s.size() - 1) {
                  x = x * 10 + s[i] - '0';
              }
              if (s[i] == '+' || i == s.size() - 1) {
                  // 输出调试
                  // cout << char(x + 'A') << y << " " << a[x - 1][y] << endl;
                  ans += a[x - 1][y];
                  x = 0;
              }
          }
          cout << ans << endl;
      }
      int main(int argc, char* argv[]) {
          int t = 1;
          // cin >> t;
          while (t--) {
              solve();
          }
          return 0;
      }
      
      
      • 1

      信息

      ID
      2083
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      (无)
      递交数
      42
      已通过
      10
      上传者