每日第二题,练题第二天

本题也是挺简单的,可以用穷举遍历来做,结果也没有超时,下面是完整的代码:
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main() {
int n,a[1000],b[1000],m,a1[1000];
cin >> n;
string s[1000];
for (int i = 0; i < n; i++) {
cin >> s[i] >> a[i] >> b[i];
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a1[i];
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a1[i] == a[j]) {
cout << s[j] << " " << b[j] << endl;
}
}
}
return 0;
}
这段代码演示了一个简单的C++程序,用于遍历两个数组并查找匹配项。程序从输入接收数组长度和元素,然后搜索目标数组中的匹配项并打印对应字符串。适合初学者理解数组操作和穷举遍历策略。
202

被折叠的 条评论
为什么被折叠?



