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:为什么我的这个代码用GCC可以过,用C就说Compile Error呢?代码应该是没问题的,VS里面编译运行都没问题。In Reply To:为什么我的这个代码用GCC可以过,用C就说Compile Error呢?代码应该是没问题的,VS里面编译运行都没问题。 Posted by:cppforever at 2014-04-15 00:52:49 > // MyPojProject.cpp : 定义控制台应用程序的入口点。 > // > > #include <stdio.h> > char s[7];//初始值 > int n;//幂 > int res[152];//计算结果 > int tmpres[152];//计算用临时变量 > int decimalCount = 0;//小数位数 > int numCount = 0;//数字位数, 5或6 > > //计算一次乘积 > void MultiLongNumbers() > { > int reslen = 151; > while (res[reslen]==0) > { > reslen --; > } > for (int i = 0; i< numCount; i++) > { > for (int j = 0; j<= reslen; j++) > { > tmpres[i+j] += s[i]*res[j]; > } > } > for (int i = 0; i<= numCount+reslen; i++) > { > if (tmpres[i] > 9) > { > tmpres[i+1] += tmpres[i]/10; > tmpres[i] = tmpres[i]%10; > } > res[i] = tmpres[i]; > tmpres[i] = 0; > } > }; > > int main() > { > int tmp; > while(scanf("%s%d", s, &n)==2) > { > tmp = 0; > for (int i = 0; i<6; i++) > { > if (s[i] == '.') > { > decimalCount = 5 - i; > tmp = 1; > } > s[i] = s[i+tmp]; > } > numCount = 6 - tmp; > //调整为低位下标为0 > for (int i = 0; i+i < numCount; i++) > { > tmp = s[i]; > s[i] = s[numCount - i - 1]; > s[numCount - i - 1] = tmp; > } > for (int i = 0; i< numCount; i++) > { > s[i] -= '0'; > } > for (int i = 0; i< 152; i++) > { > res[i] = 0; > tmpres[i] = 0; > } > res[0] = 1; > for (int i = 0; i < n; i++) > { > MultiLongNumbers(); > } > int resBeg = 151; > int resEnd = 0; > while (res[resBeg]==0) > { > resBeg --; > } > while (res[resEnd]==0) > { > resEnd ++; > } > decimalCount *= n;//结果中小数位数 > while (resBeg >= decimalCount) > { > printf("%d", res[resBeg]); > resBeg -- ; > } > if (resBeg >= resEnd) > { > printf("."); > } > while (decimalCount-1 > resBeg) > { > printf("0"); > decimalCount -- ; > } > while (resBeg >= resEnd) > { > printf("%d", res[resBeg]); > resBeg -- ; > } > printf("\n"); > } > return 0; > } void MultiLongNumbers() { ... for (int i = 0; i<= numCount+reslen; i++) {...} for (int i = 0; i<= numCount+reslen; i++) {...} } void main() { similar things: define all vavibles before statements } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator