首页 > 试题广场 >

牛牛学立体

[编程题]牛牛学立体
  • 热度指数:15702 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定一个长方体的长 a、宽 b 和高 c,请计算该长方体的表面积和体积。

【提示】
\hspace{15pt}对于不熟悉几何表面积、体积求法的同学,可以参考下面的公式:
\hspace{23pt}\bullet\,表面积:\displaystyle S = 2(ab + bc + ca)
\hspace{23pt}\bullet\,体积:\displaystyle V = abc

输入描述:
\hspace{15pt}在一行中输入三个整数 a,b,c \left(1 \leqq a,b,c \leqq 10^3\right),表示长、宽和高。


输出描述:
\hspace{15pt}第一行输出一个整数,表示表面积 S
\hspace{15pt}第二行输出一个整数,表示体积 V
示例1

输入

1 1 1

输出

6
1

说明

\hspace{15pt}在这个样例中:
\hspace{23pt}\bullet\,表面积:S = 2 \times (1\times 1 + 1\times 1 + 1\times 1) = 6
\hspace{23pt}\bullet\,体积:V = 1 \times 1 \times 1 = 1

备注:
本题已于下方时间节点更新,请注意题解时效性:
1. 2025-06-03 优化题面文本与格式。
2. 2025-06-05 优化题面文本与格式。
3. 2025-11-07 优化题面文本与格式,新增若干组数据。
封装一个简单类
#include <iostream>
using namespace std;

class Cuboid{
public:
    Cuboid(int a, int b, int c){
        this->m_a = a;
        this->m_b = b;
        this->m_c = c;
    }

    void getCuboidS(){
        cout << 2 * (m_a*m_b + m_a*m_c + m_b*m_c) << endl;
    }

    void getCuboidV(){
        cout << m_a*m_b*m_c << endl;
    }

private:
    int m_a;
    int m_b;
    int m_c;    

};

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    Cuboid cuboid(a,b,c);
    cuboid.getCuboidS();
    cuboid.getCuboidV();

    return 0;
}

发表于 2025-12-08 01:52:00 回复(0)
a,b,c = map(int,input().split())

if a < 1:
    print("输入错误,1≦a")
    exit()
if c > 1000:
    print("输入错误,c≦1000")
    exit()
S = 2 * ((a * b) + (b * c) + (c * a))
V = a * b * c
print(S)
print(V)
发表于 2025-07-24 09:31:38 回复(0)
a, b, c = map(int, input().split())

S = 2 * (a*b + b*c + c*a)
V = a*b*c

print(f"{S}\n{V}")
发表于 2025-07-13 04:56:41 回复(0)
a,b,c = map(int,input().split())
s = 2*(a*b+b*c+c*a)
v = a*b*c
print(s)
print(v)
发表于 2025-12-07 18:34:13 回复(0)
a,b,c = map(int,input().split())
s = (a*b+b*c+c*a)*2
v = a*b*c
print(s)
print(v)

发表于 2025-11-09 22:26:07 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        //使用Scanner输入长方形的长,宽,高
        Scanner sc=new Scanner(System.in);
        //定义3个整数变量,表示长方形的长,宽,高
        int a,b,c;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        //定义一个整数变量S,表示表面积,并打印
        int S=2*(a*b+b*c+a*c);
        System.out.println(S);
        //定义一个整数变量V,表示体积,并打印
        int V=a*b*c;
        System.out.println(V);
    }
}
发表于 2025-10-31 15:18:41 回复(0)
a,b,c=map(int,input().split())
S=2*(a*b+b*c+c*a)
V=a*b*c
print("{}\n{}".format(S,V))
发表于 2025-10-31 08:42:28 回复(0)
#include <stdio.h>

int main() {
    int a,b,c,S,V;
    scanf("%d %d %d",&a,&b,&c);
    S =2*(a*b+b*c+c*a);
    V =a*b*c;
    printf("%d\r\n%d",S,V);
    return 0;
}
发表于 2025-10-26 16:05:09 回复(0)
#include <stdio.h>

int main() {
    int a, b, c, V, S = 0;
    scanf("%d %d %d\r\n", &a, &b, &c);

    if (a < 1 || a > 1000) {

        printf("输入的长度超过范围,请重新输入\r\n");

        return -1;

    } else if (b < 1 || b > 1000) {

        printf("输入的宽度超过范围,请重新输入\r\n");

        return -2;

    } else if (c < 1 || c > 1000) {

        printf("输入的高度超过范围,请重新输入\r\n");
       
        return -3;

    } else {           //前面的做条件限制输入

        S = 2 * (a * b + b * c + c * a);

        V = a * b * c;

    }

    printf("%d\r\n", S);

    printf("%d\r\n", V);

    return 0;
}
发表于 2025-10-02 21:10:41 回复(0)
//道友们,注意题目里限制a<1&&c>1000哟
#include <stdio.h>
#include <stdlib.h>

int main() {
    int a, b,c;
    scanf("%d%d%d", &a, &b,&c);
    if(a<1||c>1000){
        printf("输入错误,a<1且c>1000");
        // return 0;
        exit(0);
    }
    printf("%d\n%d\n",2*(a*b+b*c+c*a),a*b*c);
   
    return 0;
}

发表于 2025-09-28 15:43:52 回复(0)
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int s = 2 * a * b + 2 * a * c + 2 * b * c, v = a * b * c;
    printf("%d\n%d", s, v);
    return 0;
}

发表于 2025-09-17 23:00:38 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
       
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int s = 0;
            int v = 0;
            if(a>=1&&a<=1000)
            {
                if(b>=1&&b<=1000)
                {
                    if(c>=1&&c<=1000)
                    {
                        s = 2*(a*b+b*c+c*a);
                        v = a*b*c;
                    }
                }
            }
            System.out.println(s);
            System.out.print(v);

        }
}
发表于 2025-09-15 00:20:30 回复(0)
自己写的,感觉好理解一点
#include <stdio.h>

int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    long long S= 2*(a*b+b*c+c*a);
    long long V=a*b*c;
    printf("%ld\n%ld",S,V);
    return 0;
}

发表于 2025-09-08 10:03:48 回复(0)
#include <stdio.h>

#define CUBOID_SURFACE_AREA(L, W, H) (2 * ((L) * (W) + (W) * (H) + (H) * (L)))
#define CUBOID_VOLUME(L, W, H) ((L) * (W) * (H))

int main() {
    int a = 0, b = 0, c = 0;

    scanf("%d %d %d", &a, &b, &c);
    
    printf("%d\n%d", CUBOID_SURFACE_AREA(a, b, c), CUBOID_VOLUME(a, b, c));

    return 0;
}

发表于 2025-08-05 20:07:49 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a, b,c;
    cin >> a >> b >>c;

    cout << 2*(a*b+b*c+c*a) << endl;
    cout << a*b*c << endl;

}
// 64 位输出请用 printf("%lld")
发表于 2025-08-05 18:57:10 回复(0)
use std::io;

fn main() {

    let mut stdin = String::new();

    io::stdin()
        .read_line(&mut stdin)
        .expect("");

    let num: Vec<i64> = stdin
        .split_whitespace()
        .map(|x| x.parse().expect(""))
        .collect();

    let a = num[0];
    let b = num[1];
    let c = num[2];

    let s = 2 * (a * b + b * c + c * a);
    let v = a * b * c;

    println!("{}\n{}", s, v);

}
发表于 2025-07-18 17:53:03 回复(0)
#include <iostream>
using namespace std;

int main() {
    int a,b,c;
    cin >> a>>b>>c;
    cout << 2*(a*b+b*c+c*a) << endl;
    cout << a*b*c ;

}

发表于 2025-07-14 11:19:50 回复(0)
#include <stdio.h>

int main() {
    int a,b,c;
    if(scanf("%d %d %d",&a,&b,&c) != 3){
        printf("输入错误!\n");
        return 1;
    }
    if(a<1 || a>1000 || b<1 || b>1000 || c<1 || c>1000){
        printf("输入错误,不在范围内!\n");
        return 1;
    }
    int Area = 2*(a*b+a*c+b*c);
    int Volume = a*b*c;
    printf("%d\n%d",Area,Volume);
    return 0;
}

发表于 2025-06-30 18:18:39 回复(0)
a,b,c = map(int,input().split())
print("%d\n%d"%(a*b*2+a*c*2+b*c*2,a*b*c))
发表于 2025-06-29 17:03:07 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            System.out.println(2 * (a * b + a * c + b * c));
            System.out.println(a * b * c);
        }
    }
}
发表于 2025-06-06 11:51:31 回复(0)