A - Division

A - Division

Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where 2 ≤ N ≤ 79. That is, abcde fghij = N where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero. Input Each line of the input file consists of a valid integer N. An input of zero is to terminate the program. Output Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator). Your output should be in the following general form: xxxxx / xxxxx = N xxxxx / xxxxx = N . .
In case there are no pairs of numerals satisfying the condition, you must write ‘There are no solutions for N.’. Separate the output for two different values of N by a blank line.

Sample Input

61
62
0

Sample Output

There are no solutions for 61.
79546 / 01283 = 62
94736 / 01528 = 62
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int N, a, b, c, d, e, f, g, h, i, j, x, y;
    int t = 0, r = 0;
    while(scanf("%d", &N) && N !=0)
    {
        if(r >= 1)
        printf("\n");
        for(f = 0; f < 5; f++)
        for(g = 0; g < 10; g++)
        {
            if (g == f) continue;
            for(h = 0; h < 10; h++)
            {

                if(h == f || h == g) continue;
                for(i = 0; i < 10; i++)
                {
                    if(i == f || i == g || i == h) continue;
                    for(j = 0; j < 10; j++)
                    {
                        if(j == f || j == g || j == h || j == i) continue;
        {
            x =10000*f + 1000*g + 100*h + 10*i + j;
            y = N * x;
            e = y % 10; y = y / 10;
            d = y % 10; y = y / 10;
            c = y % 10; y = y / 10;
            b = y % 10; y = y / 10;
            a = y % 10; y = y / 10;
            if(y <= 0)
            {
                if(a != b && a != c && a != d && a != e && a != f && a != g && a != h && a != i && a != j &&
                   b != c && b != d && b != e && b != f && b != g && b != h && b != i && b != j &&
                   c != d && c != e && c != f && c != g && c != h && c != i && c != j &&
                   d != e && d != f && d != g && d != h && d != i && d != j &&
                   e != f && e != g && e != h && e != i && e != j &&
                   f != g && f != h && f != i && f != j &&
                   g != h && g != i && g != j &&
                   h != i && h != j &&
                   i != j
                   )
                    {
                        printf("%d%d%d%d%d / %d%d%d%d%d = %d\n", a, b, c, d, e, f, g, h, i, j ,N);
                        t++;
                    }
            }
         }
                    }
                }
            }
         }
         if(t == 0) printf("There are no solutions for %d.\n", N);
         t = 0;
         r++;
    }
    return 0;
}
   空行的问题  第一次输入最前面没有空行,只有在后续的输入中才有空行的输出
当然可以!下面是对这段 ABAP 代码的**逐句详细解释**,包括语法、作用、逻辑含义和相关变量说明。 --- ### ✅ 原始代码: ```abap SELECT SINGLE * FROM zmm1000t051 AS a INTO @DATA(gs_t051) WHERE matkl = @is_mara-matkl. ``` #### 🔍 解释: 1. **`SELECT SINGLE *`** - 从数据库表中只查询**一条记录**(最多一条)。 - `*` 表示选择表中所有字段。 2. **`FROM zmm1000t051 AS a`** - 查询的数据库表是 `zmm1000t051`。 - `AS a` 是为表起一个别名 `a`,在复杂查询中方便引用。 3. **`INTO @DATA(gs_t051)`** - 将查询结果存入一个**局部结构体变量 `gs_t051`**。 - `DATA(gs_t051)` 表示声明一个局部变量 `gs_t051`,其结构与表 `zmm1000t051` 一致。 - `@` 表示这是在 `OPEN SQL` 中使用内联声明变量(ABAP 7.40+ 支持)。 4. **`WHERE matkl = @is_mara-matkl`** - 查询条件:字段 `matkl`(物料组)等于传入参数 `is_mara-matkl`。 - `@` 表示将 ABAP 内部变量带入 SQL 查询中。 --- ### ✅ 接下来是条件判断: ```abap IF gs_t051 IS NOT INITIAL AND sy-subrc = 0. ``` #### 🔍 解释: - `gs_t051 IS NOT INITIAL` - 判断结构体 `gs_t051` 是否被成功赋值(即不是空结构)。 - 如果查询成功,`gs_t051` 就会被填充数据。 - `sy-subrc = 0` - `sy-subrc` 是系统变量,表示上一条语句的执行结果。 - `0` 表示查询成功并返回一条记录。 > ✅ **综上**:只有当查询成功并返回有效数据时才进入 `IF` 分支。 --- ### ✅ 设置 BAPI 结构字段值: ```abap ls_bapimara-division = gs_t051-spart. ls_bapimarax-division = abap_true. ``` #### 🔍 解释: - `ls_bapimara-division` 是 SAP BAPI 结构 `bapi_mara` 中的字段,表示**产品组**。 - `gs_t051-spart` 来自配置表 `zmm1000t051`,赋值给 `ls_bapimara`。 - `ls_bapimarax-division = abap_true` - `ls_bapimarax` 是 `bapi_marax` 类型,用于标识哪些字段在调用 BAPI 时需要更新。 - `abap_true` 表示字段 `division` 需要被更新。 --- ```abap ls_bapimara-item_cat = gs_t051-mtpos_mara. ls_bapimarax-item_cat = abap_true. ``` - `item_cat` 表示物料的**普通项目类别组**。 - `mtpos_mara` 是配置表中定义的值,赋值给 `ls_bapimara`。 - `abap_true` 表示该字段需要更新。 --- ```abap ls_bapihead-matl_type = gs_t051-mtart. ls_mara-mtart = gs_t051-mtart. ``` - `matl_type` 是 `bapi_mathead` 中的字段,表示**物料类型**。 - `mtart` 是 `mara` 表中的标准字段,也同步赋值。 --- ### ✅ ELSE 分支(查询失败时): ```abap ELSE. et_ret = VALUE #( BASE et_ret ( matnr = is_mara-matnr type = 'E' message = |物料组{ gs_t051-matkl }的集团级参数配置表未维护| ) ). RETURN. ``` #### 🔍 解释: - 如果没有查询到数据(即 `sy-subrc ≠ 0` 或者 `gs_t051` 是空结构): - 使用 `VALUE` 构造器将一条错误信息追加到 `et_ret` 返回表中。 - `matnr`:物料编号,来自传入结构 `is_mara`。 - `type = 'E'`:表示错误类型(Error)。 - `message`:错误信息,使用 `|...|` 构造字符串,插入了 `gs_t051-matkl`(物料组)。 - 实际显示类似:`物料组ABC的集团级参数配置表未维护` - `RETURN`:立即退出当前子程序 `FORM`,不再继续执行后续代码。 --- ## ✅ 总结 | 代码片段 | 功能说明 | |----------|----------| | `SELECT SINGLE * ... INTO @DATA(gs_t051)` | 从自定义表 `zmm1000t051` 查询一条数据 | | `IF gs_t051 IS NOT INITIAL AND sy-subrc = 0` | 判断是否查到有效数据 | | `ls_bapimara-division = gs_t051-spart` 等 | 将配置值赋给 BAPI 结构字段 | | `ls_bapimarax-xxx = abap_true` | 标记这些字段需要更新 | | `ELSE` 块 | 如果未查到数据,则添加错误信息并返回 | | `RETURN` | 终止当前 `FORM` 子程序 | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值