2 solutions
-
2
#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
Information
- ID
- 921
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 2
- Tags
- # Submissions
- 71
- Accepted
- 42
- Uploaded By