Acwing4652. 纸张尺寸(十三届蓝桥杯C组真题)

在 ISO 国际标准中定义了 A0 纸张的大小为 1189mm×841mm,将 A0 纸沿长边对折后为 A1 纸,大小为 841mm×594mm,在对折的过程中长度直接取下整(实际裁剪时可能有损耗)。

将 A1 纸沿长边对折后为 A2 纸,依此类推。

输入纸张的名称,请输出纸张的大小。

输入格式

输入一行包含一个字符串表示纸张的名称,该名称一定是 A0、A1、A2、A3、A4、A5、A6、A7、A8、A9 之一。

输出格式

输出两行,每行包含一个整数,依次表示长边和短边的长度。

输入样例1:

A0

输出样例1:

1189
841

输入样例2:

A1

输出样例2:

841
594

AC代码 

//主要就是模拟
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define x first
#define y second

using namespace std;

pair<int, int> a[10];

int main()
{
    a[0].x = 1189, a[0].y = 841;
    for (int i = 1; i <= 9; i ++ )
    {
        a[i].x = max(a[i - 1].y, a[i - 1].x / 2);      
        a[i].y = min(a[i - 1].y, a[i - 1].x / 2);  
    }

    int n;
    scanf("A%d", &n);   // 格式化输入
    cout << a[n].x << endl << a[n].y << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_52030368/article/details/128680514