PTA 공통 조상

6215 단어
#include 
#include 
void find(int *a,int i,int j)
{
    if(a[i]==0)
    {
        printf("ERROR: T[%d] is NULL
"
,i); return; } if(a[j]==0) { printf("ERROR: T[%d] is NULL
"
,j); return; } while(1) { if(i==j)break; else { if(i>j) i=i/2; else j=j/2; } } printf("%d %d
"
,i,a[i]); } int main() { int a[1100],i,j,n; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d%d",&i,&j); find(a,i,j); return 0; }

좋은 웹페이지 즐겨찾기