SHARE
TWEET

Untitled

a guest Dec 8th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // PROBLEM B
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. struct employeeData{
  6.   char name[21];
  7.   // int resign;
  8.   int retire;
  9.   int fill;
  10. }employee[101];
  11.  
  12. int emp = 0;
  13.  
  14. void addEmployee(char newName[]){
  15.   int add=1;
  16.   if(emp!=0){
  17.     for(int x=0; x<emp; x++){
  18.       int compare = strcmp(newName, employee[x].name);
  19.       if(employee[x].fill==1 && employee[x].retire==0 && compare==0){
  20.         // printf("Same name!\n");
  21.         add = 0;
  22.         break;
  23.       }
  24.     }
  25.     if(add==1){
  26.       for(int x=0; x<emp; x++){
  27.         if(employee[x].fill==0 && employee[x].retire==0){
  28.           strcpy(employee[x].name, newName);
  29.           // employee[x].resign = 0;
  30.           employee[x].fill = 1;
  31.           add = 0;
  32.           emp++;
  33.           break;
  34.         }
  35.       }
  36.     }
  37.   }
  38.   if(add==1){
  39.     strcpy(employee[emp].name, newName);
  40.     employee[emp].fill = 1;
  41.     emp++;
  42.   }
  43. }
  44.  
  45. void swapEmployee(int a, int b){
  46.   if(employee[a].retire==0 && employee[b].retire==0 && employee[a].fill==1 && employee[b].fill==1){
  47.     char temp[21];
  48.     strcpy(temp, employee[a].name);
  49.     strcpy(employee[a].name, employee[b].name);
  50.     strcpy(employee[b].name, temp);
  51.   }
  52. }
  53.  
  54. void resignEmployee(int a){
  55.   if(employee[a].retire==0){
  56.     employee[a].fill = 0;
  57.   }
  58. }
  59.  
  60. void retireEmployee(int a){
  61.   if(employee[a].fill==1){
  62.     employee[a].retire = 1;
  63.     employee[a].fill = 0;
  64.   }
  65. }
  66.  
  67. void printEmployee(){
  68.   for(int x=0; x<emp; x++){
  69.     if(employee[x].fill==1){
  70.       printf("%s\n", employee[x].name);
  71.     }
  72.   }
  73. }
  74.  
  75. int main(){
  76.  
  77.   int N;
  78.   scanf("%d", &N);
  79.   for(int n=0; n<N; n++){
  80.     int process;
  81.     scanf("%d", &process); getchar();
  82.  
  83.     if(process==1){ //add
  84.       char newName[21];
  85.       scanf("%[^\n]", &newName); getchar();
  86.       scanf("%*s"); getchar();
  87.       scanf("%*s"); getchar();
  88.       // printf("%s\n", newname);
  89.       addEmployee(newName);
  90.     }
  91.     else if(process==2){
  92.       int emp1, emp2;
  93.       scanf("%d %d", &emp1, &emp2); getchar();
  94.       // printf("%d %d", emp1, emp2);
  95.       swapEmployee(emp1-1, emp2-1);
  96.     }
  97.     else if(process==3){
  98.       int empresign;
  99.       scanf("%d", &empresign); getchar();
  100.       resignEmployee(empresign-1);
  101.     }
  102.     else if(process==4){
  103.       int empretire;
  104.       scanf("%d", &empretire); getchar();
  105.       retireEmployee(empretire-1);
  106.     }
  107.  
  108.   }
  109.  
  110.   printEmployee();
  111.  
  112.   return 0;
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top