int main()
{
    char str[] = "Fatima";
     reversestr(str);
    printf("\nThe reverse is %s", str);
    return 0;
}
示例#2
0
文件: acm495.cpp 项目: ssi-anik/acm
int main()
{
    fabSeries *head,*nptr,*tptr;
	head=NULL;
	char f0[MAX],f1[MAX], Result[MAX];
	int i=0;
	nptr = new(fabSeries);
	strcpy(nptr->fabValue,"0");
	nptr->value = 0;
	nptr->next = NULL;
	head=tptr=nptr;
	nptr=new(fabSeries);
	strcpy(nptr->fabValue,"1");
	nptr->value=1;
	nptr->next=NULL;
	tptr->next=nptr;
	tptr=nptr;
	strcpy(f0,head->fabValue);
	strcpy(f1,nptr->fabValue);
	for(i=2;i<=5000;i++)
	{
		nptr = new(fabSeries);
		nptr->value = i;
		Result[0]='\0';
		call_addition(f0,f1,Result);
		strcpy(nptr->fabValue,Result);
		nptr->next=NULL;
		tptr->next=nptr;
		tptr=nptr;
		strcpy(f0,f1);
		strcpy(f1,Result);


	}
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		for(tptr=head;tptr->value!=n;tptr= tptr->next)
			;
		reversestr(tptr->fabValue,Result);
		if(n==0)
		{
			printf("The Fibonacci number for 0 is 0\n");
			continue;
		}
		for(i=0;Result[i]=='0';i++)
			;
		printf("The Fibonacci number for %d is %s\n",n,&Result[i]);
	}

	return 0;
}
示例#3
0
文件: 232.c 项目: leolas95/c
/* 
 * Basically it just merge all of the elementes of "s" into aux, so for example, if:
 *
 * s[0] = "Hello" and s[1] = "world"
 *
 * then:
 * aux[MAX] = "Helloworld"
 *
 */
int mergestr(char s[][MAX], int len)
{
	int i, k, j = 0;
	char aux[MAX];

	for (i = 0; i < len; i++) {
		for (k = 0; s[i][k] != '\0'; k++) {
			aux[j++] = s[i][k];
		}
	}
	aux[j] = '\0';		/*Never forget the null terminator*/
	return (reversestr(aux) ? 1 : 0);
}
示例#4
0
文件: acm369.cpp 项目: ssi-anik/acm
int main()
{
	int i,j,k;
	char finalResult[MAX],Result[MAX],intToString[100],intToStringFinal[100];
	for(i=0;i<=1000;i++)
	{
		nptr = new(factorial);
		if(i==0)
		{
			nptr->num=i;
			strcpy(nptr->fValue,"1");
			nptr->next=NULL;
			head=NULL;
			head=tptr=nptr;
		}
		else if (i==1)
		{
			nptr->num = i;
			strcpy(nptr->fValue,"1");
			nptr->next=NULL;
			tptr->next=nptr;
			tptr = nptr;
		}
		else if(i==2)
		{
			nptr->num = i;
			strcpy(nptr->fValue,"2");
			nptr->next=NULL;
			tptr->next=nptr;
			tptr = nptr;
		}
		else if (i==3)
		{

			nptr->num = i;
			strcpy(nptr->fValue,"6");
			nptr->next =NULL;
			tptr->next=nptr;
			tptr = nptr;
		}
		else if (i==4)
		{
			nptr->num = i;
			nptr->next = NULL;
			strcpy(nptr->fValue,"42");
			tptr->next = nptr;
			tptr = nptr;
		}
		else
		{
			if(i==5)
				strcpy(finalResult,"42");
			sprintf(intToString,"%d",i);
			reversestr(intToString,intToStringFinal);
			call_mult(finalResult,intToStringFinal,Result);
			strcpy(nptr->fValue,Result);
			nptr->num=i;
			nptr->next=NULL;
			tptr->next=nptr;
			tptr=nptr;
			strcpy(finalResult,Result);
		}
	}
	double N,M;
	while (scanf("%lf %lf",&N,&M)!=EOF)
	{
		if(N==0 && M==0)
			break;
		char ResultForN[MAX],ResultForM[MAX],ResultForNminusM[MAX];
		ResultForM[0]=ResultForN[0]=ResultForNminusM[0]='\0';
		for(tptr=head,i=0;tptr->num<=N+1;tptr=tptr->next,++i)
		{
			if(tptr->num == N)
				strcpy(ResultForN,tptr->fValue);
			if(tptr->num == M)
				strcpy(ResultForM,tptr->fValue);
			if(tptr->num == N-M)
				strcpy(ResultForNminusM,tptr->fValue);
		}
		strcpy(Result,ResultForN);
		reversestr(Result,ResultForN);
		double factOfN = atof(ResultForN);
		strcpy(Result,ResultForM);
		reversestr(Result,ResultForM);
		double factOfM = atof(ResultForM);
		strcpy(Result,ResultForNminusM);
		reversestr(Result,ResultForNminusM);
		double factOfN_M = atof(ResultForNminusM);
		long double lower = factOfN_M*factOfM;
		long double C = (long double) factOfN /( (long double) lower);
		printf("%.0lf things taken %.0lf at a time is %.0llf exactly.\n",N,M,C);
	}

    return 0;
}
示例#5
0
文件: acm623.cpp 项目: ssi-anik/acm
int main()
{
	int i,j,k;
	char finalResult[MAX],Result[MAX],intToString[100],intToStringFinal[100];
	for(i=0;i<=1000;i++)
	{
		nptr = new(factorial);
		if(i==0)
		{
			nptr->num=i;
			strcpy(nptr->fValue,"1");
			nptr->next=NULL;
			head=NULL;
			head=tptr=nptr;
		}
		else if (i==1)
		{
			nptr->num = i;
			strcpy(nptr->fValue,"1");
			nptr->next=NULL;
			tptr->next=nptr;
			tptr = nptr;
		}
		else if(i==2)
		{
			nptr->num = i;
			strcpy(nptr->fValue,"2");
			nptr->next=NULL;
			tptr->next=nptr;
			tptr = nptr;
		}
		else if (i==3)
		{

			nptr->num = i;
			strcpy(nptr->fValue,"6");
			nptr->next =NULL;
			tptr->next=nptr;
			tptr = nptr;
		}
		else if (i==4)
		{
			nptr->num = i;
			nptr->next = NULL;
			strcpy(nptr->fValue,"42");
			tptr->next = nptr;
			tptr = nptr;
		}
		else
		{
			if(i==5)
				strcpy(finalResult,"42");
			sprintf(intToString,"%d",i);
			reversestr(intToString,intToStringFinal);
			call_mult(finalResult,intToStringFinal,Result);
			strcpy(nptr->fValue,Result);
			nptr->num=i;
			nptr->next=NULL;
			tptr->next=nptr;
			tptr=nptr;
			strcpy(finalResult,Result);
		}
	}
	while (scanf("%d",&i)!=EOF)
	{
		printf("%d!\n",i);
		for(tptr=head;tptr->num!=i;tptr=tptr->next)
			;
		reversestr(tptr->fValue,Result);
		for(i=0;Result[i]=='0';i++)
			;
		printf("%s\n",Result);
	}

    return 0;
}
示例#6
0
文件: main.c 项目: jdbrandon/cmich
int main()
{
	struct timeval t1,t2;
	int count, data[22] = { 1, 2, 3, -3, -99, 999, 42, 14, 56, 
				76, 99, 12, -2345, 3456789, 199, 123,
				234, -567, -999, 21, 32, -12345};
	int z,i;
	i=0;
	long long timeleaf, timenorm, difference;
	void lstringcpy(char *dst, char *src);
	void stringcpy(char *dst, char *src);
	void lstringcat(char *dst, char *src);
	void stringcat(char *dst, char *src);
	void lreversestr(char *st);
	void reversestr(char *st);
	void lstringucase(char *st);
	void stringucase(char *st);
	void lstringlcase(char *st);
	void stringlcase(char *st);
	int lstringcmp(char *str1, char *str2);
	int stringcmp(char *str1, char *str2);
	int lcntofevens(int *list, int n);
	int cntofevens(int *list, int n);
	int lfindlargest(int *list, int n);
	int findlargest(int *list, int n);
	int lcntlessthanx(int *list, int n, int x);
	int cntlessthanx(int *list, int n, int x);
	int lcntofmultiplesof8(int *list, int n);
	int cntofmultiplesof8(int *list, int n);
	
	timeleaf = 0; timenorm = 0;
	
	while(i<100000){
	char astr[64] = "A long long string is here!!";
	char astr2[64]= "A long long string is here!!";
	char *str = "True";
	char *str2= "True";
	char s[4]="Tru";
	char s2[4]="Tru";
	char *t="e";
	char *st2="e";
	char backwards[15]="eurT";
	char backwards2[15]="eurT";
	/* start timer for leaf */
	gettimeofday(&t1,NULL);
	lstringcpy(astr, str);
	lstringcat(s,t);
	lreversestr(backwards);
	lstringucase(s);
	lstringlcase(s);
	z = lstringcmp(s,str);
	count = lcntofevens(data, 22);
	count = lfindlargest(data, 22);
	count = lcntlessthanx(data,22,0);
	count = lcntofmultiplesof8(data,22);
	gettimeofday(&t2,NULL);
	/* end timer for leaf */
	timeleaf+=t2.tv_usec-t1.tv_usec;	
	/* start timer for normal */
	gettimeofday(&t1,NULL);
	stringcpy(astr2, str2);
	stringcat(s2,st2);
	reversestr(backwards2);
	stringucase(s2);
	stringlcase(s2);
	z = stringcmp(s2,str2);
	count = cntofevens(data, 22);
	count = findlargest(data, 22);
	count = cntlessthanx(data,22,0);
	count = cntofmultiplesof8(data,22);
	gettimeofday(&t2,NULL);
	/* end timer for normal */
	timenorm+=t2.tv_usec-t1.tv_usec;
	difference=timenorm-timeleaf;
	i++;
	}
	printf("leaf time: %lld\nnormal time: %lld\ndifference: %lld\n",timeleaf,timenorm,difference);
	exit(0);
}