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 |
晕,竟是2000位以内的#include <stdio.h> #include <string.h> int SigDigit(int nInput) { if (nInput < 10) return nInput; int nSum = 0; while(nInput != 0) { nSum += nInput % 10; nInput /= 10; } return SigDigit(nSum); } int main(int argc, char* argv[]) { char pInput[2000]; unsigned int nInput = 0; while(scanf("%s", pInput), pInput[0] != '0') { nInput = 0; for (int i = 0; i < strlen(pInput); i++) { nInput += pInput[i] - '0'; } printf("%d\n", SigDigit(nInput)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator