未通过

694 - The Collatz Sequence

#include <stdio.h>
int main()
{
	long A,L;
	long n=1;
	while(scanf("%ld%ld",&A,&L)==2)
	{
		long count=0;
		if(A<0 && L<0)
			break;
		for(;;)
		{
			count++;
			if(A==1)
				break;
			else if(A%2)
			{
				A=3*A+1;
				if(A>L)
					break;
			}
			else
				A=A/2;
		}
		printf("Case %d: A = %ld, limit = %ld, number of terms = %ld\n",n++,A,L,count);
	}
	return 0;
}

401 - Palindromes
/*#include <stdio.h>
#include <string.h>
#include <ctype.h>
char p[2][50]=
{
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789",
	"A   3  HIL JM O   2TUVWXY51SE Z  8 "
};
char str[1000];

int f(int n)
{
	int isreg,ismir,i;
	isreg=1;
	ismir=1;
	for(i=0;i<(n-1)/2 && isreg==1;i++)
	{
		if(str[i]!=str[n-1-i])
			isreg=0;
	}
	for(i=0;i<(n-1)/2 && ismir==1;i++)
	{
		if(isdigit(str[i]))
		{
			if(p[1][str[i]-'1'+26]!=str[n-1-i])
				ismir=0;
		}
		else
		{
			if(p[1][str[i]-'A']!=str[n-1-i])
				ismir=0;
		}
	}
	if(isreg==0 && ismir==0)
		return 0;
	else if(isreg==1 && ismir==0)
		return 1;
	else if(isreg==0 && ismir==1)
		return 2;
	else if(isreg==1 && ismir==1)
		return 3;
	return -1;
}

int main()
{
	while(scanf("%s",str)!=EOF)
	{
		int len;
		len=strlen(str);
		for(int i=0;i<len;i++)
			if(str[i]=='0')
				str[i]='o';
		switch(f(len))
		{
		case 0:
			printf("%s -- is not a palindrome.\n",str);
			break;
		case 1:
			printf("%s -- is a regular palindrome.\n",str);
			break;
		case 2:
			printf("%s -- is a mirrored string.\n",str);
			break;
		case 3:
			printf("%s -- is a mirrored palindrome.\n",str);
			break;
		default:
			break;
		}
		printf("\n");
	}
	return 0;
}*/

#include<stdio.h>
#include<string.h>
const char one[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
const char two[]="A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const long len=35;
bool Palindrome(const char *s)
{
    long begin=0,end=strlen(s)-1;
    while(begin<=end)
    {
       if(s[begin]==s[end])
       {
          begin++;
          end--;
       }
       else
         return false;
    }
    return true;
}
long pos(char ch)
{
    for(long i=0;i<len;i++)
      if(one[i]==ch)
        return i;
    return len;
}
bool Mirror(const char *s)
{
    long begin=0,end=strlen(s)-1;
    while(begin<=end)
    {
       long tmp=pos(s[begin]);
       if(s[end]==two[tmp])
       {
          begin++;
          end--;
       }
       else
         return false;
    }
    return true;
}
int main()
{
    char str[1000];
    while(gets(str)!=0)
    {
       bool a=false,b=false;
       a=Palindrome(str);
       b=Mirror(str);
       if(a&&b)
         printf("%s -- is a mirrored palindrome.\n",str);
       else if(a)
         printf("%s -- is a regular palindrome.\n",str);
       else if(b)
         printf("%s -- is a mirrored string.\n",str);
       else
         printf("%s -- is not a palindrome.\n",str);
       putchar('\n');
    }
return 0;
}


你可能感兴趣的:(未通过)