7-1 cm to feet inches *First day at home

7-1 cm conversion feet and inches
If you know the values ​​of foot and inch in imperial length, then the corresponding meter is (foot+inch/12)×0.3048. Now, if the user enters centimeters, what are the feet and inches that correspond to imperial lengths? Don't forget that 1 foot equals 12 inches.

Input format:
input gives 1 positive integer in one line, the unit is centimeter.

Output format:
Output this centimeter in one line as the integer value of feet and inches corresponding to the imperial length, separated by a space.

Input sample:
170
without blank lines at the end
Output sample:
5 6
without blank lines at the end

#C语言
#include<stdio.h>
int main()
{
    
    
    int x,foot,inch;
    scanf("%d",&x);
        foot = x / 30.48;
        inch = (x / 30.48 - foot) * 12;
    printf("%d %d",foot,inch);
return 0;
}
#C++
#include<iostream>
using namespace std;
int main()
{
    
    
    int x,inch,foot;
    cin>>x;
    foot = x / 30.48;
    inch = (x / 30.48 - foot) * 12;
    cout<<foot<<" "<<inch<<endl;
    return 0;
}
#java
import java.util.Scanner;
  public class Main{
    
    
  public static void main(String[] args)
    {
    
    
        int x,foot,inch;
        Scanner scan=new Scanner(System.in);
        x=scan.nextInt();
        foot =(int)(x/30.48);
        inch =(int)((x/30.48 - foot)*12);
        System.out.println(foot+" "+inch);
    }
  }
#python
x=int(input())
foot=x//(0.3048*100) #在Python中/表示浮点整除法,返回浮点结果,也就是结果为浮点数;而//在Python中表示整数除法,返回大于结果的一个最大的整数,意思就是除法结果向下取整。
inch=12*(x/(0.3048*100)-foot)
print('%d %d'%(foot,inch))

Note: Conversion common sense: 1 foot = 0.348 meters, 1 inch = 2.540005 cm, 1 meter
= 3.28084 feet, 1 cm = 0.3937 inches, 1 inch =
2.5400 cm, 1 foot = 12 inches = 0.3048 meters,
1 yard = 3 feet = 0.9144 meters, 1 mile = 1760 yards = 1.6093 kilometers
1 foot = 0.33333 meters, 1 inch = 0.1 feet

Guess you like

Origin blog.csdn.net/weixin_45867259/article/details/122343473