如何解析出图形形式的数字网格?

发布于 2024-10-19 07:31:22 字数 244 浏览 7 评论 0原文

假设所有网格都可以包含 1 到 99 之间的任意数字,那么识别每个数字的最简单方法是什么?

例如:

-------------
| 1 | 2 | 3 |
|-----------|
|11 | 12| 13|
|-----------|
|4  | 5 | 6 |
|-----------|

如何将它们解析为二维数组?语言并不重要,我只想得到一个通用的解决方案。

谢谢,

Assuming all the grids can contain any number from 1 to 99 in each, what's the simplest way to recognize each number?

For example:

-------------
| 1 | 2 | 3 |
|-----------|
|11 | 12| 13|
|-----------|
|4  | 5 | 6 |
|-----------|

How do I parse them into a 2 dimensional array? Language doesn't matter, I just want to get a general solution.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2024-10-26 07:31:22

如果您知道这是格式,我会使用正则表达式或简单的字符串分割

perl 中的示例:

REGEX:

my @data;

for( <FILE> ) {
   next unless /\d/;
   /\D*(\d+)\D+(\d+)\D+(\d+)\D*/;
   $data[$#data + 1] = ( $1, $2, $3 );
}

STRING OPS:

my @data;
for ( <FILE> ) {
    next unless /\d/;
    $data[$#data + 1] = split /|/, $_;
 }

或类似的东西。

If you know that to be the format I would go with either regex or simple string splitting

Examples in perl:

REGEX:

my @data;

for( <FILE> ) {
   next unless /\d/;
   /\D*(\d+)\D+(\d+)\D+(\d+)\D*/;
   $data[$#data + 1] = ( $1, $2, $3 );
}

STRING OPS:

my @data;
for ( <FILE> ) {
    next unless /\d/;
    $data[$#data + 1] = split /|/, $_;
 }

Or something to that effect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文