ACM 2009. 6. 8. 15:04
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
#define MAX_SIZE 20 
#define MAX_CNT 1000 
 
int isPalindrome(unsigned long long palindrome);
int palindromeFunc(unsigned long long palindrome);
 
unsigned long long g_palindromeNum;
int g_repeatCnt;
 
int main(void)
{
    int testCase, returnVal;
    unsigned long long num;
 
    scanf("%d", &testCase);
 
    while(testCase)
    {
        scanf("%llu", &num);
        returnVal = palindromeFunc(num);
        printf("%d %llu\n", g_repeatCnt, g_palindromeNum);
        testCase--;
    }
    return 0;
}
 
int palindromeFunc(unsigned long long palindrome)
{
    char numStr[MAX_SIZE], reverseNumStr[MAX_SIZE];
    int palindromeLen, i, j=0, returnVal, count=1;
    unsigned long long reversePalindrome;
 
    while(count++)
    {
        if(count==MAX_CNT) return 0;
        
        returnVal =  isPalindrome(palindrome);
        if(returnVal) {
            g_repeatCnt = count-2;
            g_palindromeNum = palindrome;
            return 1;
        }
 
        sprintf(numStr, "%llu", palindrome);
        palindromeLen = strlen(numStr);
 
        // Reverse
        for(i=palindromeLen-1, j=0; i>=0; i--){
            reverseNumStr[j++] = numStr[i];
        }
        reverseNumStr[j] = '\0';
 
        // Add
        reversePalindrome = (unsigned long long)(atoll(reverseNumStr));
        palindrome += reversePalindrome;    
    }
    return 0;
}
 
int isPalindrome(unsigned long long palindrome)
{
    char numStr[MAX_SIZE];
    int palindromeLen, i, j;
 
    snprintf(numStr, MAX_SIZE,  "%llu", palindrome);
    palindromeLen = strlen(numStr);
 
    // Check as if Reverse
    for(i=0, j=palindromeLen-1; i!=palindromeLen/2;  i++, j--)
    {
        if(numStr[i]!=numStr[j])
            return 0;
    }
    return 1;
}

반응형

'ACM' 카테고리의 다른 글

[10018] Reverse and Add  (0) 2009.06.03
[Time Limit] Carmichael Numbers  (0) 2009.06.02
[Accept] 10006 Carmichael Numbers  (0) 2009.06.02
[Accept] 10110 Light, more light  (0) 2009.06.02
[Accept] 850 Crypt Kicker II  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 3. 20:25
반응형

Reverse and Add

The Problem

The "reverse and add" method is simple: choose a number, reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number from left to right and right to left), repeat this procedure.

For example:
195 Initial number
591
-----
786
687
-----
1473
3741
-----
5214
4125
-----
9339 Resulting palindrome

In this particular case the palindrome 9339 appeared after the 4th addition. This method leads to palindromes in a few step for almost all of the integers. But there are interesting exceptions. 196 is the first number for which no palindrome has been found. It is not proven though, that there is no such a palindrome.

Task :
You must write a program that give the resulting palindrome and the number of iterations (additions) to compute the palindrome.

You might assume that all tests data on this problem:
- will have an answer ,
- will be computable with less than 1000 iterations (additions),
- will yield a palindrome that is not greater than 4,294,967,295.
 

The Input

The first line will have a number N with the number of test cases, the next N lines will have a number P to compute its palindrome.

The Output

For each of the N tests you will have to write a line with the following data : minimum number of iterations (additions) to get to the palindrome and the resulting palindrome itself separated by one space.

Sample Input

3
195
265
750

Sample Output

4 9339
5 45254
3 6666
반응형

'ACM' 카테고리의 다른 글

[Accept] 10018 Reverse and Add  (0) 2009.06.08
[Time Limit] Carmichael Numbers  (0) 2009.06.02
[Accept] 10006 Carmichael Numbers  (0) 2009.06.02
[Accept] 10110 Light, more light  (0) 2009.06.02
[Accept] 850 Crypt Kicker II  (0) 2009.06.02
posted by ssuk1010
:
ssuk's story 2009. 6. 3. 17:27
반응형

* 자율신경계 균형 무너질 때 발생

◇왜 쓰러지나

실신의 가장 흔한 원인 중 하나는 자율신경계 균형이 무너지며 기절하는 것이다.

우리 몸은 뇌·척수 등의 중추신경계를 비롯해 말초신경계·자율신경계로 구성되고, 자율신경계는 교감 및 부교감신경으로 나뉜다.

인체에는 이들 신경계가 조화를 이루면서 스스로 균형을 유지하는데, 자율 신경 장애로 인한 실신은 교감신경과 부교감신경의 균형이 깨지면서 생긴다. 부교감 신경이 우세해져혈압이 떨어지고 맥박이 느려지면서 뇌로 가는 혈액량이 부족해져 실신하게 되는 것이다.

밀폐된 공간·기침·식후 주의

◇언제 일어나는가

자율 신경계 균형이 잘 깨지는 경우는 밀폐된 장소(만원 버스·백화점·교실·교회·성당·화장실 등)에서 한 자세로 오랫동안 서 있을 때다. 한 자세로 서 있다보면 심장으로 돌아와 순환하는 혈액량이 줄어들고, 이런 경우 심장박동 수가 증가해 혈액량을 늘려줘야 하는데 자율 신경에 이상이 생기면서 뇌혈류가 부족, 기절하는 것.

또 드물긴 하지만 일어나는 상황에 따라 배뇨성·배변성·기침·식후 실신 등으로도 나뉜다. 어떤 행동을 하다 정신을 잃게 되느냐가 중요한 기준이 되는 셈이다.

배뇨성 실신은 A씨처럼 소변을 보는 도중에 실신하는 것으로, 과음을 한 뒤 잠자다 소변을 보려고 할 때 주로 일어난다. 배변 실신은 나이가 많은 사람들 중에 발생하는 경우가 많다.

기침하다가 실신하는 수도 있는데, 만성기관지염이나 담배를 많이 피우는 사람이 심한 기침을 하다 의식을 잃는 경우가 이에 해당한다. 어린이들이 발작성 기침을 하다 실신하기도 한다. 식후 실신은 식사 도중 음식물을 삼키는 과정에서 일어난다.

답답함·식은땀·메스꺼움 증상

◇치료는 어떻게 하나

자율 신경 조절 장애로 인한 실신은 가슴이 답답하고 식은땀이 흐르면서 메스껍고 힘이 없어지는 등의 증상이 먼저 나타나는 만큼 이때 바로 누이면 의식 소실은 막을 수 있다. 누워 다리를 심장 높이 이상으로 올리면 뇌로 가는 혈액이 정상화돼 곧 정상상태를 찾을 수 있다고 전문의들은 설명했다. 전문의들은 또“실신하지 않았더라도 이같은 증상을 경험한 사람들은 주의가 필요하다”고 강조한다.

이동중이라면 최대한 자세를 낮춰 앉는 것이 예방법.

배뇨성·배변성 실신 등 상황성 실신은 실신을 일으키는 특별한 상황을 피하면 충분히 막을 수 있다.

그러나 상황을 피하기 어렵거나 예측하기 힘들 때에는 베타교감신경차단제나 알파자극제·부교감신경억제제·호르몬제·항우울제 등 약물을 쓰기도 한다.

반응형

'ssuk's story' 카테고리의 다른 글

공부하기 좋은 사이트  (0) 2009.09.16
I hate the people (1)  (0) 2009.06.03
ssuk's first story  (1) 2009.06.02
posted by ssuk1010
: