hdu 4544 叛逆的小明 -- 数字反转 和 hdu 2074 叠筐(水题)

水题:数字的反转,123变成321,  复数时前导0去掉 比如-100变成-1

#include 
using namespace std;

#define N 10000

int Reverse(int inNum)
{
	int sum = 0;
	if (inNum < 10)
	{
		return inNum;
	}
	while(inNum%10 == 0) inNum /= 10;
	while(inNum)
	{
		sum = sum * 10 + inNum % 10;
		inNum /= 10;
	}

	return sum;

}

int main()
{
	int a, b, t;
	int c, d;
	scanf("%d", &t);
	while(t--)
	{	

		scanf("%d %d", &a, &b);
		c = (a + b) / 2;
		d = (a - b) / 2;

		if (c < 0)
		{
			c = Reverse(-c);
			c *= -1;
		}
		else
		{
			c = Reverse(c);
		}

		if (d < 0)
		{
			d = Reverse(-d);
			d *= -1;
		}
		else
		{
			d = Reverse(d);
		}

		printf("%d %d\n", c + d, c - d);
		
	}
	return 0;
}


hdu 2074 叠筐

注意:除了最后一个用例以外,每一个用例后面都要跟一个空白行

 

#include 
using namespace std;

#define N 80

char graph[N][N];
int main()
{
    int n, m;
    int i, j, p,q, k;
    char A, B;
	int newline = 0;
    while(scanf("%d %c %c", &n, &A, &B) != EOF)
    {
		if (newline++)
		{
			printf("\n");
		}
		if (n == 1)
		{
			
			printf("%c\n", A);
			continue;
		}
        m = (n + 1) / 2;
        if (m % 2 != 0)
        {
            char tmp = A;
            A = B;
            B = tmp;
        }

        for (i = 0;i < m; i++)
        {
            if((i % 2) == 0) 
            {
                k = n - ( 2 * i);
                for (p = i, q = 0;q < k; ++p, ++q)
                {
                    graph[i][p] = graph[n - i-1][p] = B;
                }

                for (p = i, q =0; q < k; ++p, ++q)
                {
                    graph[p][i] = graph[p][n - i - 1] = B;
                }

            }
            else
            {
                k = n - ( 2 * i );
                for (p = i, q = 0;q < k; ++p, ++q)
                {
                    graph[i][p] = graph[n - i - 1][p] = A;
                }

                for (p = i, q = 0;q < k; ++p, ++q)
                {
                    graph[p][i] = graph[p][n - i - 1] = A;
                }
            }
        }

         graph[0][0] = ' ';
         graph[0][n - 1] = ' ';
         graph[n - 1][0] = ' ';
         graph[n - 1][n - 1] = ' ';
        for (i = 0; i < n; ++i)
        {
            for (j = 0; j < n; ++j)
            {
                printf("%c", graph[i][j]);
            }
            printf("\n");
        }
    }

    return 0;
}


 

你可能感兴趣的:(c/c++,acm水题)