Cod sursa(job #2489247)

Utilizator lucianistratiIstrati Lucian lucianistrati Data 8 noiembrie 2019 09:52:08
Problema Aria Scor 0
Compilator c-64 Status done
Runda Arhiva educationala Marime 2.34 kb
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
//#include <libpthread>
//Laburi 1 , 2, 0, 1
int a[3][3],b[3][3],c[4][4];
struct Coord
{
   int x,y;
};
pthread_t Threaduri[5];
void * hello(void *v)
{
	char *who = (char*) v;
	printf("Hello, %s!", who);
	return NULL;
}

char *strrev(char *str)
{
      char *p1,*p2;
      if (!str || !*str)
            return str;
      for(p1=str,p2=str+strlen(str)-1;p2>p1;++p1,--p2)
      {
            *p1^=*p2;
            *p2^=*p1;
            *p1^=*p2;
      }
      return str;
}
void * stringReverse(void *v)
{
	char *who = (char*) v;
    char aux;
	int i;
	/*for(i=0;i<strlen(who)/2;i++)
	{
		aux=who[i];
		who[i]=who[strlen(who)-1-i];
		who[strlen(who)-1-i]=aux;
	}*/
	printf("%s\n", strrev(who));
	return NULL;
}
void init()
{
    a[0][0]=1;
	a[0][1]=2;
  	a[1][0]=3;
	a[1][1]=4;
	b[0][0]=1;
	b[0][1]=2;
  	b[1][0]=3;
	b[1][1]=4;
}

void* inmultire_element(void *v)
{
   struct Coord *Point = (struct Coord*) v;
   //Point=*Pointed;
   printf("%d %d\n",Point.x,Point.y);
   int p,px,py;
	px=Point.x;
    py=Point.y;
   c[px][py]=0;
   for(p=0;p<=1;p++)
	{
		c[px][py]+=a[px][p]*b[p][py];
	}
}
void inmultire()
{
	int i,j,p,q;
	for(i=0;i<=3;i++)
	{
		struct Coord z;
        if(i==0)
		{
 			z.x=0;
			z.y=0;
		}
		if(i==1)
		{
			z.x=0;
			z.y=1;
		}
        if(i==2)
		{
			z.x=1;
			z.y=0;
		}	
		if(i==3)
		{
			z.x=1;
			z.y=1;
		}
		//struct Coord * t= &z;
        pthread_create(&Threaduri[i], NULL, inmultire_element, z); 
    } 
    for(i=0;i<=4;i++)  
    {
	    pthread_join(Threaduri[i], NULL);
	}   
}
void afisare()
{
 	int i,j;
	for(i=0;i<=1;i++)
		{
			for(j=0;j<=1;j++)
			{
				printf("%d ",c[i][j]);
			}
		printf("\n");
		}		
}
int main(int argc, char *argv[])
{
	init();
	int i,k=0;
	pthread_t thr;
    char s[50],t[50];
    for(i=2;i<strlen(argv[0]);i++)
	{
		s[k++]=argv[0][i];
	}
	s[k]='\0';
	k=0;
	for(i=0;i<strlen(argv[1]);i++)
	{
		t[k++]=argv[1][i];
	}
	t[k]='\0';
	//printf("%s %s",s,t);	
	int result;
	//printf("hey\n");
	// -- Program 1
	if (pthread_create(&thr, NULL, stringReverse, t)) {
	  perror(NULL);
	  return errno;
	}
	if(pthread_join(thr, &result)){	
		perror(NULL);
		return errno;	
	}
	//Program 2
   inmultire();
   afisare();
}