Created
December 11, 2009 13:03
-
-
Save EragonJ/254197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<string.h> | |
#define MAX 205 | |
void mirror(char*); | |
int main(){ | |
char input[MAX][MAX]={0}; | |
char result[MAX]; | |
int i,j,count; | |
int maxlength = 0; | |
int add; | |
int carry; | |
for(i=0,count=0;i<MAX;i++,count++){ | |
scanf("%s",&input[i]); | |
if(strcmp(input[i],"0")==0) break; | |
mirror(input[i]); | |
maxlength = maxlength > strlen(input[i]) ? maxlength : strlen(input[i]); | |
} | |
for(i=0,carry=0;i<maxlength;i++){ | |
add = 0; | |
for(j=0;j<count;j++){ | |
if(input[j][i]==0) continue; | |
add += (input[j][i]-'0'); | |
} | |
add += carry ; | |
if(add>=10){ | |
carry = (add / 10); | |
}else{ | |
carry = 0; | |
} | |
result[i] = (add % 10) + '0'; | |
} | |
if(carry>0){ | |
result[i] = carry + '0'; | |
} | |
mirror(result); | |
for(i=0,count=0;i<strlen(result);i++){ | |
if(result[i]=='0'&&result[i+1]=='0'){ | |
count++; | |
continue; | |
}else{ | |
break; | |
} | |
} | |
if((count+1)==strlen(result)){ | |
printf("0"); | |
}else{ | |
for(i=0;result[i]=='0';i++); | |
for(i;i<strlen(result);i++){ | |
printf("%c",result[i]); | |
} | |
} | |
printf("\n"); | |
return 0; | |
} | |
void mirror(char* input){ | |
int i; | |
int len = strlen(input); | |
char output[MAX]={0}; | |
sprintf(output,"%s",input); | |
for(i=0;i<len;i++){ | |
input[i] = output[len-i-1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment