2017級算法第一次上機-C.蕓茹的課堂測試
阿新 • • 發佈:2018-12-11
spa strlen \n color con col std for mes
Horner Ruler 霍納規則沒什麽好說的 要註意的更多的還是細節的問題
取模運算
循環的邊界問題
#include <algorithm> #include <iostream> #include <cstring> using namespace std; const int maxlen = 1e6 + 10; const int mod = 1e9 + 7; char str[maxlen]; long long Horner(char str[]){ int len=strlen(str); long long i,j,k,ans; ans=0; for(i=0;i<len-1;i++){ ans=( ((ans%mod )+ ((str[i]-‘0‘)%mod)) % mod ) % mod * 8 % mod ; } ans= ( (ans % mod ) + ( (str[i]-‘0‘) % mod) ) % mod; return ans; } int main(){ int n; scanf("%d",&n); while(n--){ scanf("%s",str); printf("%lld\n",Horner(str)); }return 0; }
2017級算法第一次上機-C.蕓茹的課堂測試