1 条题解

  • 0
    @ 2023-9-26 22:45:54
    #include<iostream>
    #include<bits/stdc++.h>
    using namespace std;
    int ans[200];
    int Get[10];
    char Cin[10];
    int mul;
    void func(){
    	int temp[200] = {0};
    	for(int i = 1; i <= ans[0]; ++i){
    		for(int j = 1; j <= Get[0]; ++j){
    			temp[i+j-1] += ans[i]*Get[j];
    			temp[i+j] += temp[i+j-1] / 10;
    			temp[i+j-1] = temp[i+j-1] % 10;
    		}
    	}
    	int num = ans[0]+Get[0];
    	while(temp[num] == 0)num--;
    	ans[0] = num;
    	for(int i = 1; i <= num; ++i)ans[i] = temp[i];
    	return ;
    }
    int main(){
    	while(cin >> Cin >> mul){
    		int num = 1;
    		int pos = -1;
    		int flag = 0;
    		if(Cin[0] == '0')flag = 1;
    		for(int i = strlen(Cin) - 1; i >= 0; --i){
    			if(Cin[i] == '.'){
    			pos = strlen(Cin) - i;
    			continue;
    		}
    			Get[num++] = Cin[i] - '0';
    		}
    		if(pos == -1)pos = 1,Get[0] = strlen(Cin);
    		else
    			Get[0] = strlen(Cin) - 1;
    		ans[0] = Get[0];
    		for(int i = 1; i <= Get[0]; ++i)ans[i] = Get[i];
    		for(int i = 1; i < mul; ++i){
    			func();
    		}
    		int l = 1,r = ans[0];
    		while(ans[l] == 0 && l <= (pos-1)*mul)l++;
    		if(flag){
    			cout << "0.";
    			for(int i = (strlen(Cin)-2)*mul; i >= l; --i){
    				if(i > ans[0])cout << 0;
    				else
    					cout << ans[i];
    			}
    			cout << endl; 
    		}
    		else{
    		for(int i = r; i >= l; --i){
    			if(i == (pos-1) * mul)cout << '.';
    			cout << ans[i];
    		}
    		cout << endl;
    	}
    		memset(ans,0,sizeof(ans));
    		memset(Get,0,sizeof(Get));
    	}
    	return 0;
    }
    
  • 1

信息

ID
1192
时间
1000ms
内存
128MiB
难度
9
标签
递交数
35
已通过
4
上传者