fork download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. struct SinhVien
  5. {
  6. string msv;
  7. string name;
  8. string lop;
  9. string email;
  10. };
  11. void nhap(SinhVien& ds)
  12. {
  13. getline(cin, ds.msv);
  14. getline(cin, ds.name);
  15. getline(cin, ds.lop);
  16. getline(cin, ds.email);
  17. }
  18. void find(SinhVien ds[], int n, string find)
  19. {
  20. if (find == "KE TOAN") find = "DCKT";
  21. if (find == "CONG NGHE THONG TIN") find = "DCCN";
  22. if (find == "AN TOAN THONG TIN") find = "DCAT";
  23. if (find == "VIEN THONG") find = "DCVT";
  24. if (find == "DIEN TU") find = "DCDT";
  25. for (int i = 0; i < n; i++)
  26. {
  27. string k = ds[i].msv.substr(3, 4);
  28. char key = ds[i].lop[0];
  29. bool logic = true;
  30. if (find == k)
  31. {
  32. if (find == "DCAT" || find == "DCCN" )
  33. {
  34. if (key == 'E')
  35. {
  36. logic = false;
  37. }
  38. }
  39. if(logic)
  40. cout << ds[i].msv << " " << ds[i].name << " " << ds[i].lop << " " << ds[i].email << endl;
  41. }
  42.  
  43. }
  44. }
  45. void Upper(string& k)
  46. {
  47. for (int i = 0; i < k.length(); i++)
  48. {
  49. k[i] = toupper(k[i]);
  50. }
  51. }
  52. int main()
  53. {
  54. SinhVien ds[1000];
  55. int n;
  56. cin >> n;
  57. cin.ignore();
  58. for (int i = 0; i < n; i++)
  59. {
  60. nhap(ds[i]);
  61. }
  62. int sl;
  63. string k;
  64. cin >> sl;
  65. cin.ignore();
  66. while (sl--)
  67. {
  68. getline(cin, k);
  69. string title = k;
  70. Upper(title);
  71. cout << "DANH SACH SINH VIEN NGHANH " << title << ":" << endl;
  72. find(ds, n, title);
  73. }
  74. return 0;
  75. }
  76.  
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
Standard output is empty