#include <bits/stdc++.h> using namespace std; int n,t,k; string x="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; stack s; queue q; double num; void f1(int n){ while(n){ s.push(n%k); n/=k; } while(!s.empty()){ cout<<x[s.top()]; s.pop(); } } void f2(double n){ for(int i=1;i<=3;i++){ int d=nk; q.push(d); n=nk-d; } while(!q.empty()){ cout<<x[q.front()]; q.pop(); } } int main(){ cin>>t; while(t--){ cin>>num>>k; n=num; f1(n); cout<<"."; f2(num-n); cout<<endl; } return 0; }

1 条评论

  • #include #include #include #include using namespace std;

    const string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    void convertIntegerPart(int n, int k) { stack s; while (n) { s.push(n % k); n /= k; } while (!s.empty()) { cout << digits[s.top()]; s.pop(); } }

    void convertFractionalPart(double frac, int k) { queue q; for (int i = 0; i < 3; i++) { int d = static_cast(frac * k); q.push(d); frac = frac * k - d; } while (!q.empty()) { cout << digits[q.front()]; q.pop(); } }

    int main() { int t, k; double num; cin >> t;

    while (t--) {
        cin >> num >> k;
        int integerPart = static_cast<int>(num);
        double fractionalPart = num - integerPart;
        
        convertIntegerPart(integerPart, k);
        cout << ".";
        convertFractionalPart(fractionalPart, k);
        cout << endl;
    }
    
    return 0;
    

    }

    • 1

    信息

    ID
    1513
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    39
    已通过
    21
    上传者