zoj 1154 Niven numbers
生活随笔
收集整理的這篇文章主要介紹了
zoj 1154 Niven numbers
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?見zoj 1154
?還是需要將輸入數(shù)據(jù)當(dāng)作字符串來處理,不能直接使用整型。
?
/* zoj 1154 Niven numbers */#include <stdio.h> #define MAX 100 int isNivenNum(int base, char str[]);int main(void) {int totalBlocks;int base;int first = 1;char str[MAX];scanf("%d", &totalBlocks);while(totalBlocks-- > 0){if(first)first = 0;elseprintf("\n");while(scanf("%d", &base) == 1 && base != 0){scanf("%s", str);if(isNivenNum(base, str))printf("yes\n");elseprintf("no\n");}}return 0; } int isNivenNum(int base, char str[]) {int digitSum = 0, decNum = 0;int temp;int i;for(i = 0; str[i] != '\0'; i++){temp = str[i] - '0';digitSum += temp;decNum = base *decNum + temp;}if(decNum % digitSum == 0)return 1;elsereturn 0; } ??
總結(jié)
以上是生活随笔為你收集整理的zoj 1154 Niven numbers的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬虫 正则表达式 re.fi
- 下一篇: math for programmers