Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct record{
  5. char name[21];
  6. int resign;
  7. int retire;
  8. };
  9.  
  10. struct record lili[101];
  11.  
  12. int nameDoesntExist(char name[21]){
  13. int notFound=1;
  14. int i=0;
  15. for(i=0; lili[i].name[0]!=0 ; i++){
  16.  
  17. if(lili[i].retire==1)continue;
  18. if(lili[i].resign==1)continue;
  19.  
  20. if(strcmp( lili[i].name, name)==0){
  21. notFound = 0;
  22. return 0; //same name found
  23. break;
  24. }
  25. }
  26. if(notFound)return 1; //same name not found
  27. }
  28.  
  29. void add(char name[21]){
  30. // printf("Adding new record %s\n",name);
  31. if( nameDoesntExist(name) ){
  32. // printf("--> %s doesn't Exist, adding new record...\n",name);
  33. for(int i=0;; i++ ){
  34. if( (lili[i].name[0]==0) || ((lili[i].resign==1)&&(lili[i].retire==0))
  35. ){
  36. // printf("--> empty element/retired found on [%d]! Record added to [%d]\n", i+1, i+1);
  37. strcpy(lili[i].name,name);
  38. lili[i].resign=0;
  39. lili[i].retire=0;
  40. break;
  41. }
  42. }
  43. }else{
  44. // printf("%s Exists, skipping this one.\n",name);
  45. }
  46. }
  47.  
  48. void swap(int a, int b){
  49. // printf("Swapping record [%d] with [%d]\n", a+1,b+1);
  50. if( (lili[a].resign==0) && (lili[b].resign==0)
  51. && (lili[a].retire==0) && (lili[b].retire==0)
  52. && (lili[a].name[0]!=0) && (lili[b].name[0]!=0)){
  53. char temp[21];
  54. strcpy(temp, lili[a].name);
  55. strcpy(lili[a].name, lili[b].name);
  56. strcpy(lili[b].name, temp);
  57.  
  58. int temp2 = lili[a].resign;
  59. lili[a].resign = lili[b].resign;
  60. lili[b].resign = temp2;
  61. // printf("--> Swapped!\n");
  62. } else {
  63. // printf("--> error:one of the position has resigned\n");
  64. }
  65.  
  66. }
  67.  
  68. void resign(int a){
  69. // printf("Marking record [%d] as resigned\n",a+1);
  70. if(lili[a].retire==0){
  71. lili[a].resign = 1;
  72. }
  73. }
  74.  
  75. void retire(int a){
  76. // printf("Marking record [%d] as retired\n",a+1);
  77. if(lili[a].resign==0){
  78. lili[a].retire = 1;
  79. }
  80. }
  81.  
  82. void display(){
  83. for(int i=0; lili[i].name[0] != 0; i++){
  84. printf("[%d] %s | %d | %d\n",i+1,lili[i].name,lili[i].resign,lili[i].retire);
  85. }
  86. }
  87.  
  88. int main(){
  89. int input=0;
  90. scanf("%d", &input);
  91. for(int i=0;i<input;i++){
  92. int process;
  93. // printf("input #%d: ",i);
  94. scanf("%d", &process);
  95. if(process==1){
  96. char a[21],b[21],c[21];
  97. scanf("%s %s %s",a,b,c);
  98. add(a);
  99. } if(process==2){
  100. int a,b;
  101. scanf("%d %d",&a,&b);
  102. swap(a-1,b-1);
  103. } if(process==3){
  104. int a;
  105. scanf("%d", &a);
  106. resign(a-1);
  107. } if(process==4){
  108. int a;
  109. scanf("%d", &a);
  110. retire(a-1);
  111. }
  112. }
  113. for(int i=0; lili[i].name[0]!=0 ;i++){
  114. if( lili[i].resign == 1)continue;
  115. if( lili[i].retire == 1)continue;
  116. printf("%s\n",lili[i].name);
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement