练手,模拟法...
感叹以前自己居然不懂,复杂度o(n).
- #include
- using namespace std;
- struct cube
- {
- unsigned int digit:4;
- };
- cube digit[100000],res[100000];
- int main()
- {
- int r,c,t,i,l;char tmp;
- while(1)
- {
- r=t=l=0;
- while((tmp=getchar())>='0'&&tmp<='9')digit[r++].digit=tmp-'0';
- cin>>c;
- for(i=0;i
- {
- t=10*t+digit[i].digit;
- res[l++].digit=t/c;
- t%=c;
- }
- for(i=0;i
- cout<<'/'<'=';
- for(i=0;iif(res[i].digit)break;
- for(;i
- cout<
- for(i=0;i
- cout<<'%'<'='<
- getchar();
- }
- return 0;
- }