Coder

舒心、快乐,比什么都重要

1041 考试座位号 (15 分)

// 自己写的还行吧,数组不要忘了开的大一点;
#include <iostream> using namespace std; struct str { string id; int sj; int ks; } s[1010]; int main(){ int n, m, x; cin >> n; for (int i = 0; i < n; i++){ cin >> s[i].id >> s[i].sj >> s[i].ks; } cin >> m; while (m--){ cin >> x; for (int i = 0; i < n; i++){ if (x == s[i].sj) cout << s[i].id << ' ' << s[i].ks << endl; } } return 0; }


//这个是网上的大神的,思路很特别
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 1e3 + 10;
struct stu {
    string num;
    int y;
}a[maxn];
int n, m;
int main()
{
    scanf("%d", &n);
    while (n--)
    {
        string s;
        int x, y;
        cin >> s >> x >> y;
        a[x].num = s;
        a[x].y = y;
    }
    scanf("%d", &m);
    while (m--)
    {
        int q;
        scanf("%d", &q);
        cout << a[q].num << " " << a[q].y << endl;
    }
    return 0;
}

 

 

 

posted @ 2019-04-21 21:41  H123K  阅读(236)  评论(0编辑  收藏  举报