Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:帮我看看我的程序,老是wrong answer,我确定没有错误啊,是不是格式有要求啊?In Reply To:Re:帮我看看我的程序,老是wrong answer,我确定没有错误啊,是不是格式有要求啊? Posted by:chavez1986 at 2009-08-05 12:12:10 > 不知道为什么,就是加了个不一定是6个数字的处理,修改如下: > /* > ============================================================================ > Name : 1001-exponentiation.c > Author : gsj > Version : > Copyright : Your copyright notice > Description : Hello World in C, Ansi-style > ============================================================================ > */ > > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > > #define MAX_LENGHT 5*25 > > > int main(void) { > //input > char szLine[6]; > int n; > > //output > int result[MAX_LENGHT]; > > //middle > int a[5];//被乘数 > int b[MAX_LENGHT];//乘数 > while (scanf("%s%d", szLine, &n) != EOF) { > //loop index > int i, j, k; > > //flag > int dflag = 0; > int count = 0, dot = 0; > int length, dotPosition, start,m; > int sLength; > //x^0 > if (n == 0) { > printf("1\n"); > continue; > } > //initialization > memset(result, 0, MAX_LENGHT * sizeof(int)); > memset(b, 0, MAX_LENGHT * sizeof(int)); > memset(a, 0, 5 * sizeof(int)); > b[0] = 1; > > //szLine's length > sLength = strlen(szLine); > //判断有没有小数点 > for (i = 0; i < sLength; i++) { > if (szLine[i] == '.' && i != 5) > dflag = 1; > } > > //deal with input > j = 0; > for (i = 0; i <= 5; i++) { > if (dflag) { > if (szLine[sLength -1 - i] == '0') { > if (szLine[sLength -2 - i] != '0') > dflag = 0; > dot--; > continue; > }else > dflag = 0; > } > > if (szLine[sLength -1 - i] != '.') { > a[j] = szLine[sLength -1 - i] - '0'; > count += a[j]; > j++; > } else > dot += i; > } > > //0^n(n!=1) > if (count == 0) { > printf("0\n"); > continue; > } > > //1^n > if(count == 1 && a[0] == 1){ > printf("1\n"); > continue; > } > > //multiply > for (k = 0; k < n; k++) { > for (i = 0; i < 5; i++) > for (j = 0; j < MAX_LENGHT; j++) > result[i + j] += a[i] * b[j]; > > for (i = 0; i < MAX_LENGHT; i++) { > if (result[i] >= 10) { > result[i + 1] += result[i] / 10; > result[i] %= 10; > } > } > if (k == n - 1) > break; > for (i = 0; i < MAX_LENGHT; i++) { > b[i] = result[i]; > result[i] = 0; > } > > } > > //length > length = 0; > for (i = MAX_LENGHT - 1; i >= 0; i--) { > if (result[i]) { > length = i + 1; > break; > } > } > > //dot's position > dotPosition = dot * n; > m = length - dot * n; > > if (m <= 0) { > printf("."); > for (j = -m; j > 0; j--) { > printf("0"); > } > > } > start = 0; > for (i = MAX_LENGHT - 1; i >= 0; i--) { > if (i == dotPosition - 1 && m > 0) > printf("."); > if (start == 1) > printf("%d", result[i]); > else if (result[i]) { > printf("%d", result[i]); > start = 1; > } > > } > printf("\n"); > } > return 0; > } > AC了还是很开心的 嘎嘎 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator