2 solutions

  • 2
    @ 2023-10-25 16:52:15
    #include <bits/stdc++.h>
    using namespace std;
    
    void ForEach(void * a, int width, int num,void (*f)(void * p)) {// 在该行补充你的代码
        for(int i = 0; i < num; ++i)
            f((char*)a + width * i);
    }
    
    void PrintSquare(void * p) {
        int * q = (int*)p;
        int n = *q;
        cout << n * n << ",";
    }
    
    void PrintChar(void * p) {
        char * q = (char*)p;
        cout << *q << ",";
    }
    
    int main() {
        int a[5] = {1, 2, 3, 4, 5};
        char s[] = "hello!";
        ForEach(a, sizeof(int), 5, PrintSquare);
        cout << endl;
        ForEach(s, sizeof(char), 6, PrintChar);
        return 0;
    }
    
    • 1
      @ 2024-10-23 17:02:17
      #include<bits/stdc++.h>
      using namespace std;
      
      int main() 
      {
          cout << "1,4,9,16,25," << endl;
      	cout << "h,e,l,l,o,!,";
      
          return 0;
      }
      
      • 1

      Information

      ID
      921
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      2
      Tags
      # Submissions
      71
      Accepted
      42
      Uploaded By