首页 新闻 会员 周边 捐助

c++窗口 C++C++C++

0
悬赏园豆:50 [已解决问题] 解决于 2024-10-12 20:47

窗口
提交数: 76, 通过率: 34.21%, 平均分: 47.24
题目描述:
Boudreaux 通常把九个程序一起运行。由于显示器资源的有限,他把窗口重叠,并且当他要用某个窗口的时候,他就把它调到最前端。如果他的显示器是一个 4 x 4 的方格,Boudreaux的每一个窗口就应该像下面那样用2 x 2的窗口表示:

1534407660771862627.png
当Boudreaux 把一个窗口调到前端的时候,它的所有方格都到最前,覆盖它与其它窗口共用的方格。例如,如果窗口 1 然后 窗口 2 被调到当前, 结果应该表达为:

1534407680886144157.png

. . . 等等等等 . . .

不幸的是, Boudreaux的电脑很不稳定。他通过观察窗口是否正确地被调到当前,一眼就能看出电脑是否死机。(其实学校机房的电脑经常这样)你的任务来了 . . .

输入格式:
输入包含最多100组数据。每组数据将按下列描述给出,各组数据间无空行。

单组数据包含 3 部分:

START
用四行表示当前Boudreaux的显示器状态。为使输入简单点,数字间仅用一个空格分开。
END

最后一组数据后,会有一行:

ENDOFINPUT

注意每个小块只能出现在它可能出现的地方。例如 1 只能出现在左上方的四个小格里。

输出格式:
对每个数据只输出一行。如果能按一定顺序调出窗口达到数据描述的那样(即没死机),输出:

THESE WINDOWS ARE CLEAN

否则:

THESE WINDOWS ARE BROKEN

样例输入:
START
1 2 3 3
4 5 6 6
7 8 9 9
7 8 9 9
END
START
1 1 3 3
4 1 3 3
7 7 9 9
7 7 9 9
END
ENDOFINPUT
样例输出:
THESE WINDOWS ARE CLEAN
THESE WINDOWS ARE BROKEN
时间限制: 1000ms
空间限制: 256MB
求c++代码

kiry7769的主页 kiry7769 | 初学一级 | 园豆:15
提问于:2024-09-21 14:23
< >
分享
最佳答案
0

你这题目的图片也没显示出来呀

收获园豆:50
Smalldy | 菜鸟二级 |园豆:496 | 2024-10-08 14:42

并且这个问题站内就有题解 https://www.cnblogs.com/SBSOI/p/5872912.html 你可否试下?

Smalldy | 园豆:496 (菜鸟二级) | 2024-10-08 14:47

@Smalldy: 谢谢

kiry7769 | 园豆:15 (初学一级) | 2024-10-12 20:53
其他回答(1)
-1

根据题目描述,我们需要判断给定的显示器状态能否按照指定的顺序调出窗口。这可以通过模拟窗口的调整过程来实现。
下面是一个可能的C++代码实现:

include <iostream>

include <vector>

bool isClean(std::vector<std::vector<int>>& display) {
int n = display.size();

for (int i = 0; i < n; i += 2) {
    for (int j = 0; j < n; j += 2) {
        if (display[i][j] != display[i][j+1] || display[i][j] != display[i+1][j] || display[i][j] != display[i+1][j+1]) {
            return false;
        }
    }
}

return true;

}
int main() {
std::string input;

while (std::getline(std::cin, input) && input != "ENDOFINPUT") {
    std::vector<std::vector<int>> display(4, std::vector<int>(4));
    
    if (input == "START") {
        for (int i = 0; i < 4; i++) {
            std::string line;
            std::getline(std::cin, line);
            std::istringstream iss(line);
            
            for (int j = 0; j < 4; j++) {
                iss >> display[i][j];
            }
        }
        
        std::getline(std::cin, input); // Read the "END" line
        
        if (isClean(display)) {
            std::cout << "THESE WINDOWS ARE CLEAN" << std::endl;
        } else {
            std::cout << "THESE WINDOWS ARE BROKEN" << std::endl;
        }
    }
}

return 0;

}
该代码首先定义了一个 isClean 函数来判断显示器状态是否是干净的(窗口都是完整的)。
然后在 main 函数中,我们循环读取每组数据。在每组数据中,我们依次读取显示器状态,并将它存储在 display 二维向量中。
最后,我们调用 isClean 函数来判断显示器状态是否干净,并根据判断结果输出对应的字符串。
请注意,这只是一个可能的实现,具体实现方式可以根据实际需要进行调整。

Technologyforgood | 园豆:7692 (大侠五级) | 2024-09-23 08:05

编译错误
Main.cc:1:1: error: ‘include’ does not name a type
1 | include <iostream>
| ^~~~~~~
Main.cc: In function ‘int main()’:
Main.cc:17:6: error: ‘string’ is not a member of ‘std’
17 | std::string input;
| ^~~~~~
Main.cc:1:1: note: ‘std::string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’?
+++ |+#include <string>
1 | include <iostream>
Main.cc:19:13: error: ‘getline’ is not a member of ‘std’
19 | while (std::getline(std::cin, input) && input != "ENDOFINPUT") {
| ^~~~~~~
Main.cc:19:26: error: ‘cin’ is not a member of ‘std’
19 | while (std::getline(std::cin, input) && input != "ENDOFINPUT") {
| ^~~
Main.cc:1:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
+++ |+#include <iostream>
1 | include <iostream>
Main.cc:19:31: error: ‘input’ was not declared in this scope; did you mean ‘int’?
19 | while (std::getline(std::cin, input) && input != "ENDOFINPUT") {
| ^~~~~
| int
Main.cc:20:10: error: ‘vector’ is not a member of ‘std’
20 | std::vector<std::vector<int>> display(4, std::vector<int>(4));
| ^~~~~~
Main.cc:1:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
+++ |+#include <vector>
1 | include <iostream>
Main.cc:20:22: error: ‘vector’ is not a member of ‘std’
20 | std::vector<std::vector<int>> display(4, std::vector<int>(4));
| ^~~~~~
Main.cc:20:22: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
Main.cc:20:29: error: expected primary-expression before ‘int’
20 | std::vector<std::vector<int>> display(4, std::vector<int>(4));
| ^~~
Main.cc:24:18: error: ‘string’ is not a member of ‘std’
24 | std::string line;
| ^~~~~~
Main.cc:24:18: note: ‘std::string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’?
Main.cc:25:18: error: ‘getline’ is not a member of ‘std’
25 | std::getline(std::cin, line);
| ^~~~~~~
Main.cc:25:31: error: ‘cin’ is not a member of ‘std’
25 | std::getline(std::cin, line);
| ^~~
Main.cc:25:31: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
Main.cc:25:36: error: ‘line’ was not declared in this scope
25 | std::getline(std::cin, line);
| ^~~~
Main.cc:26:18: error: ‘istringstream’ is not a member of ‘std’
26 | std::istringstream iss(line);
| ^~~~~~~~~~~~~
Main.cc:1:1: note: ‘std::istringstream’ is defined in header ‘<sstream>’; did you forget to ‘#include <sstream>’?
+++ |+#include <sstream>
1 | include <iostream>
Main.cc:29:17: error: ‘iss’ was not declared in this scope
29 | iss >> display[i][j];
| ^~~
Main.cc:29:24: error: ‘display’ was not declared in this scope
29 | iss >> display[i][j];
| ^~~~~~~
Main.cc:33:14: error: ‘getline’ is not a member of ‘std’
33 | std::getline(std::cin, input); // Read the "END" line
| ^~~~~~~
Main.cc:33:27: error: ‘cin’ is not a member of ‘std’
33 | std::getline(std::cin, input); // Read the "END" line
| ^~~
Main.cc:33:27: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
Main.cc:35:21: error: ‘display’ was not declared in this scope
35 | if (isClean(display)) {
| ^~~~~~~
Main.cc:35:13: error: ‘isClean’ was not declared in this scope
35 | if (isClean(display)) {
| ^~~~~~~
Main.cc:36:18: error: ‘cout’ is not a member of ‘std’
36 | std::cout << "THESE WINDOWS ARE CLEAN" << std::endl;
| ^~~~
Main.cc:36:18: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
Main.cc:36:60: error: ‘endl’ is not a member of ‘std’
36 | std::cout << "THESE WINDOWS ARE CLEAN" << std::endl;
| ^~~~
Main.cc:1:1: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
+++ |+#include <ostream>
1 | include <iostream>
Main.cc:38:18: error: ‘cout’ is not a member of ‘std’
38 | std::cout << "THESE WINDOWS ARE BROKEN" << std::endl;
|
不会可以选择不答,ai我也会问,再说ai能解决100%的问题吗,他回答的我早就试了,能解决的话我早试过了,别拿鸡毛当令箭,博文全是这种,晦气

支持(0) 反对(0) kiry7769 | 园豆:15 (初学一级) | 2024-09-28 14:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册