PAT基础编程题目集7-1 厘米换算英尺英寸

7-1 厘米换算英尺英寸

题目链接-7-1 厘米换算英尺英寸
在这里插入图片描述
解题思路

  • 根据题目公式可得:n×0.01=(foot+inch/12)×0.3048
    化简得n×0.01/0.3038=foot+inch/12
  • 因为一英尺(foot)等于十二英寸(inch),这样我们可以就理解为foot是等式左边的整数部分,而inch/12为等式左边的小数部分
  • 所以对等式左边数值取整即得foot值,n×0.01/0.3038-foot即为小数部分,即inch/12,所以可得inch=(n×0.01/0.3038-foot)×12
  • 具体操作见代码

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	double n;
	cin>>n;
	n=n*0.01/0.3048;
	int f=(int)n;
	int i=(n-f)*12;
	cout<<f<<" "<<i;
	return 0;
}

发布了123 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Fiveneves/article/details/104677776
今日推荐