E - Find The Multiple

本文介绍了一个编程问题:给定一个正整数n,如何找出一个非零倍数m,使得m的十进制表示中只包含0和1这两个数字。文章提供了一种使用深度优先搜索算法来解决该问题的方法,并通过示例输入输出展示了程序运行效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.
Input
The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.
Output
For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
#include <iostream>
#include <queue>

using namespace std;
int n,flag;
void dfs(long long cur,int step)
{
    if(step == 19 || flag) return;///当m为19位时,会超出longlong的范围类型
    if(cur % n == 0)
    {
        flag = 1;
        cout << cur << endl;
        return;
    }
    dfs(cur*10,step+1);///两种的选择,增加1或者0
    dfs(cur*10+1,step+1);
}

int main()
{
    while(cin>>n&&n)
    {
        flag = 0;
        dfs(1,0);///开始的时候,m只能是1,并且增加的位数是0
 }
    return 0;
}

OPTIONS: --Werror - If set, changes formatting warnings to errors --assume-filename=<string> - Override filename used to determine the language. When reading from stdin, clang-format assumes this filename to determine the language. --cursor=<uint> - The position of the cursor when invoking clang-format from an editor integration --dry-run - If set, do not actually make the formatting changes --dump-config - Dump configuration options to stdout and exit. Can be used with -style option. --fallback-style=<string> - The name of the predefined style used as a fallback in case clang-format is invoked with -style=file, but can not find the .clang-format file to use. Use -fallback-style=none to skip formatting. --ferror-limit=<uint> - Set the maximum number of clang-format errors to emit before stopping (0 = no limit). Used only with --dry-run or -n --help - Display available options (--help-hidden for more) -i - Inplace edit <file>s, if specified. --length=<uint> - Format a range of this length (in bytes). Multiple ranges can be formatted by specifying several -offset and -length pairs. When only a single -offset is specified without -length, clang-format will format up to the end of the file. Can only be used with one input file. --lines=<string> - <start line>:<end line> - format a range of lines (both 1-based). Multiple ranges can be formatted by specifying several -lines arguments. Can't be used with -offset and -length. Can only be used with one input file. -n - Alias for --dry-run --offset=<uint> - Format a range starting at this byte offset. Multiple ranges can be formatted by specifying several -offset and -length pairs. Can only be used with one input file. --output-replacements-xml - Output replacements as XML. --sort-includes - If set, overrides the include sorting behavior determined by the SortIncludes style flag --style=<string> - Coding style, currently supports: LLVM, Google, Chromium, Mozilla, WebKit. Use -style=file to load style configuration from .clang-format file located in one of the parent directories of the source file (or current directory for stdin). Use -style="{key: value, ...}" to set specific parameters, e.g.: -style="{BasedOnStyle: llvm, IndentWidth: 8}" --verbose - If set, shows the list of processed files --version - Display the version of this program
最新发布
07-23
<think>我们正在讨论clang-format工具,用户希望了解其命令行选项的详细用法。根据引用[1],我们知道clang-format是一个代码格式化工具,用于自动化统一代码风格。引用[1]还提到可以通过命令行或编辑器插件使用它。引用[2]则提到可以在保存文件时自动格式化,比如在VSCode中配置。 由于用户明确要求命令行选项的详解,我们将重点介绍clang-format的命令行选项。根据Clang官方文档,clang-format的命令行选项主要包括: 1. 指定样式(-style):可以是预定义样式(如LLVM, Google, Chromium, Mozilla, WebKit)或使用特定文件(如.clang-format或_clang-format)或直接指定样式字符串。 2. 指定输出方式(-i):表示直接修改文件,而不是输出到标准输出。 3. 指定文件或目录(当指定目录时会递归处理该目录下的文件)。 4. 其他选项如-assume-filename(用于在没有打开文件时指定文件名以确定样式)等。 下面我们将详细解释这些选项。</think>### Clang-Format 命令行选项详解 Clang-Format 是一个强大的代码格式化工具,通过命令行选项可以灵活控制格式化行为。以下是常用命令行选项的详细说明: #### 1. **基本格式化选项** - **`-i`**:直接修改源文件(原地格式化) 示例:`clang-format -i main.cpp` 将直接修改 main.cpp 文件 - **`--style=<value>`**:指定代码风格 支持预定义风格(如 `LLVM`, `Google`, `Chromium`)或配置文件路径: ```bash clang-format --style=Google file.cpp # 使用预定义风格 clang-format --style=file file.cpp # 使用目录中的 .clang-format 文件 ``` - **`-fallback-style=<value>`**:当无配置文件时的回退样式(默认:`LLVM`) 示例:`clang-format -fallback-style=WebKit file.h` #### 2. **输出控制选项** - **`-output-replacements-xml`**:输出 XML 格式的替换指令(用于工具集成) 示例:`clang-format -output-replacements-xml file.c` - **`-dump-config`**:输出当前生效的配置 示例:`clang-format --style=Google -dump-config > .clang-format` - **`-n`**:仅检查是否需要格式化(不修改文件),返回 0 表示无需修改 示例:`clang-format -n --Werror *.h` 结合 `-Werror` 可集成到 CI #### 3. **范围控制选项** - **`-lines=<start>:<end>`**:仅格式化指定行范围 示例:`clang-format -lines=10:20 file.py` - **`-offset=<N>`** + **`-length=<L>`**:格式化从偏移量 N 开始的 L 个字符 示例:`clang-format -offset=100 -length=50 file.java` #### 4. **诊断与调试选项** - **`-Werror`**:将警告视为错误(适用于 CI 检查) 示例:`clang-format -i -Werror src/*.c` - **`-verbose`**:显示详细处理信息 示例:`clang-format -verbose --style=LLVM *.cpp` #### 5. **特殊场景选项** - **`-assume-filename=<name>`**:强制指定文件名(影响语言检测) 示例:`cat input | clang-format -assume-filename=test.h` - **`-sort-includes`**:启用/禁用 include 排序(需配置文件中开启) 示例:`clang-format -sort-includes=false file.cc` > 完整选项列表可通过 `clang-format --help` 查看,或参考官方文档[^1]。 ### 配置优先级说明 Clang-Format 按以下顺序确定配置: 1. 命令行 `--style` 直接指定的配置 2. 项目目录中的 `.clang-format` 或 `_clang-format` 文件 3. 用户全局配置(`~/.clang-format`) 4. `-fallback-style` 指定的回退配置 ### 典型工作流示例 ```bash # 1. 生成默认配置文件 clang-format -style=Google -dump-config > .clang-format # 2. 批量格式化整个项目 find src/ -name '*.cpp' -exec clang-format -i {} \; # 3. CI 集成检查 clang-format --Werror --dry-run src/*.c ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值