Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:C code

Posted by sonlic at 2011-12-10 22:12:01 on Problem 1001
In Reply To:C code Posted by:ayxg at 2011-12-07 14:26:15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 101
/*
 * 
 */
int main() {
    char num[7];
    char result[MAX];
    int inputNo,count,j,k,dotPos,s,middleValue = 0,i = 0;
    while(scanf("%s %d",num,&count) == 2)
    {
        i = 0;
        if(count <= 0 || count > 25) return -1;
        while(num[i] != '.' && num[i] != '\0')
            i++;

        if(i > 2) return -1;
        dotPos = (strlen(num)-i-1) * count;
        printf("%d",dotPos);
        for(j = i;j < 7;j++)
            num[j] = num[j+1]; 
        for(j = 0;j<MAX;j++)
            result[j] = 0;
         result[0] = 1;
         inputNo = atoi(num);

         while(count > 0)
         {
             for(j = 0; j < MAX;j++ )
             {
                s = inputNo * result[j] + middleValue;                
                middleValue = s/10;
                result[j] = s % 10;
             }
             count--;
         }
         
         if(num[0] == '0')
         {
             j = -1;
             while(result[++j] == 0);
             printf("%c",'.');
             k = j + dotPos -1;
             while(k >= j)
             {
                 printf("%d",result[k]);
                 k--;
             }
         }
         else
         {
             j = MAX;
             k = -1;
             while(result[--j] == 0);
             while(result[++k] == 0);
             while(j >= k)
             {
                 printf("%d",result[j]);
                 if(j == dotPos)
                     printf("%c",'.');
                 j--;
             }
         }
         printf("\n");
    }
    
    return 1;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator