Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- struct calendar
- {
- char *eveniment;
- int data;
- }*a;
- int string_compare(char *s1, char *s2)
- {
- int i=0, j=0;
- for(; *(s1+i) && *(s2+j); i++, j++)
- if(*(s1+i)>*(s2+j))
- return 1;
- else if(*(s1+i)<*(s2+j))
- return -1;
- if(*(s1+i))
- return 1;
- if(*(s2+j))
- return -1;
- return 0;
- }
- void citire(int n)
- {
- a=(struct calendar*)malloc((n+1)*sizeof(struct calendar));
- for(int i=0; i<n; i++)
- (a+i)->eveniment=(char*)malloc(265*sizeof(char));
- for(int i=0; i<n; i++)
- {
- scanf("%*c%[^\n]s",(a+i)->eveniment);
- scanf("%d", &(a+i)->data);
- }
- }
- void afisare(int n)
- {
- for(int i=0; i<n; i++)
- printf("%s %d\n", (a+i)->eveniment, (a+i)->data);
- }
- int main()
- {
- int test, n, poz;
- scanf("%d", &test);
- switch(test)
- {
- case 1://citire + afisare
- scanf("%d", &n);
- citire(n);
- afisare(n);
- break;
- case 2://citire + sortare + aisare
- scanf("%d", &n);
- citire(n);
- for(int i=0; i<n-1; i++)
- for(int j=i+1; j<n; j++)
- if((a+i)->data>(a+j)->data)
- {
- struct calendar aux;
- aux=*(a+i);
- *(a+i)=*(a+j);
- *(a+j)=aux;
- }
- afisare(n);
- break;
- case 3://strcmp
- char *s1, *s2;
- s1=(char*)malloc(256*sizeof(char));
- s2=(char*)malloc(256*sizeof(char));
- scanf("%*c%[^\n]s",s1);
- scanf("%*c%[^\n]s",s2);
- printf("%d", string_compare(s1, s2));
- break;
- case 4://adauga evenimentul din poz i
- scanf("%d", &n);
- citire(n);
- poz;
- struct calendar b;
- b.eveniment=(char*)malloc(265*sizeof(char));
- scanf("%*c%[^\n]s",b.eveniment);
- scanf("%d", &b.data);
- scanf("%d", &poz);
- for(int i=n; i>=poz; i--)
- *(a+i)=*(a+(i-1));
- *(a+poz)=b;
- n++;
- afisare(n);
- break;
- case 5://sterge evenimentul x
- scanf("%d", &n);
- citire(n);
- char *s;
- s=(char*)malloc(256*sizeof(char));
- scanf("%*c%[^\n]s",s);
- poz=-1;
- for(int i=0; i<n; i++)
- if(string_compare(s, (a+i)->eveniment)==0)
- poz=i, i=n;
- if(poz>0)
- {
- for(int i=poz; i<n-1; i++)
- *(a+i)=*(a+(i+1));
- n--;
- }
- afisare(n);
- break;
- }
- }
- /*
- ////1
- 1
- 5
- colocviu pc
- 20240117
- test chimie
- 20240119
- test fizica
- 20240108
- partial analiza
- 20231125
- examen analiza
- 20240122
- ///2
- 2
- 5
- colocviu pc
- 20240117
- test chimie
- 20240119
- test fizica
- 20240108
- partial analiza
- 20231125
- examen analiza
- 20240122
- ///3
- 3
- asdddd
- asddd
- ///4
- 4
- 5
- colocviu pc
- 20240117
- test chimie
- 20240119
- test fizica
- 20240108
- partial analiza
- 20231125
- examen analiza
- 20240122
- examen peda
- 20240123
- 3
- ///5
- 5
- 5
- colocviu pc
- 20240117
- test chimie
- 20240119
- test fizica
- 20240108
- partial analiza
- 20231125
- examen analiza
- 20240122
- partial analiza
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement