Game Outcome

A - Game Outcome
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winningif the sum of the column numbers is strictly greater than the sum of the row numbers.

For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.

Input

<p< p="">

The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Output

<p< p="">

Print the single number — the number of the winning squares.

Sample Input

Input
1
1
Output
0
Input
2
1 2
3 4
Output
2
Input
4
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3
Output
6

Hint

<p< p="">

In the first example two upper squares are winning.

In the third example three left squares in the both middle rows are winning:

5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3

解题报告:

以网格中每个数字为基准, 统计列和大于行和的个数。

Code:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>

using namespace std;

const int MAXN = 35;
int check[MAXN][MAXN];
int c[MAXN], r[MAXN];

int main()
{
    memset(check, 0, sizeof check);
    memset(c, 0, sizeof c);
    memset(r, 0, sizeof r);

    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> check[i][j];
            r[i] += check[i][j];
        }
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            c[i] += check[j][i];
        }
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(c[j] > r[i])
                cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}



Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
The programme should have the following features: ● A menu including Open and Exit where Open starts a JFileChooser to select the file with the questions inside and Exit ends the programme. ● Once a file is loaded, the GUI should display one question and its answers at a time. ● The user should be able to select an answer and they should be informed if they were correct or not. ● The user should be made aware of the number of correctly answered and the total number of questions answered. ● The user should only be able to proceed to the next question once they answered the current one. ● Once all questions have been answered, the user should be informed of their overall score and that the game has finished. The Open menu item should now be enabled to start a new quiz. Optionally, you can add a restart menu item to redo the current quiz. Concrete sub-tasks: a) define a class called Question to hold a single question, i.e. the text, the possible answers, and the correct answer index; (0.25P) b) write a method to select a file via a JFileChooser and to read all the questions from that file into an array/list of Question objects (assume that file has the structure mentioned above); (0.25P) c) design and implement a GUI with the components mentioned above: A menu, ability to display the question and answers, ability to select an answer, show the outcome and score, and proceed to the next question. (Appropriate layout: 1P, Class extends JFrame: 0.25P, Class follows OOP principles: 0.25P, Global set-up in main method: 0.25P)1 d) write a method to display a question on the GUI you designed; (0.25P) e) implement an actionPerformed method to respond to user interactions with the GUI. Make sure to enable and disable interactive components as required, e.g. the user should not be able to skip to the next question without selecting an answer first and they should not be able to load a new quiz before finishing the current one;
05-29
Thank you for your detailed requirements. Based on your requirements, here are the steps you can follow to build the program: 1. Define a class called `Question` that holds a single question, i.e. the text, the possible answers, and the correct answer index. Here's an example implementation: ``` class Question: def __init__(self, text, answers, correct_answer_index): self.text = text self.answers = answers self.correct_answer_index = correct_answer_index ``` 2. Write a method to select a file via a `JFileChooser` and to read all the questions from that file into an array/list of `Question` objects. Here's an example implementation: ``` def load_questions(): file_chooser = JFileChooser() result = file_chooser.showOpenDialog(None) if result == JFileChooser.APPROVE_OPTION: file = file_chooser.getSelectedFile() questions = [] with open(file) as f: for line in f: parts = line.strip().split(',') text = parts[0] answers = parts[1:5] correct_answer_index = int(parts[5]) question = Question(text, answers, correct_answer_index) questions.append(question) return questions ``` Assuming the file has the structure mentioned in your requirements, this method will read all the questions from the file into a list of `Question` objects. 3. Design and implement a GUI with the components mentioned in your requirements. Here's an example implementation: ``` class QuizApp(JFrame): def __init__(self): super().__init__() self.questions = [] self.current_question_index = 0 self.correct_answers_count = 0 self.init_ui() def init_ui(self): self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) self.setTitle('Quiz App') self.create_menu() self.create_question_panel() self.create_answers_panel() self.create_buttons_panel() self.create_status_panel() self.pack() self.setLocationRelativeTo(None) def create_menu(self): menu_bar = JMenuBar() file_menu = JMenu('File') open_item = JMenuItem('Open') open_item.addActionListener(self.handle_open) exit_item = JMenuItem('Exit') exit_item.addActionListener(self.handle_exit) file_menu.add(open_item) file_menu.add(exit_item) menu_bar.add(file_menu) self.setJMenuBar(menu_bar) def create_question_panel(self): self.question_label = JLabel() self.add(self.question_label) def create_answers_panel(self): self.answers_button_group = ButtonGroup() self.answer_1_button = JRadioButton() self.answer_2_button = JRadioButton() self.answer_3_button = JRadioButton() self.answer_4_button = JRadioButton() self.answers_button_group.add(self.answer_1_button) self.answers_button_group.add(self.answer_2_button) self.answers_button_group.add(self.answer_3_button) self.answers_button_group.add(self.answer_4_button) answers_panel = JPanel() answers_panel.add(self.answer_1_button) answers_panel.add(self.answer_2_button) answers_panel.add(self.answer_3_button) answers_panel.add(self.answer_4_button) self.add(answers_panel) def create_buttons_panel(self): self.submit_button = JButton('Submit') self.submit_button.addActionListener(self.handle_submit) self.next_button = JButton('Next') self.next_button.setEnabled(False) self.next_button.addActionListener(self.handle_next) buttons_panel = JPanel() buttons_panel.add(self.submit_button) buttons_panel.add(self.next_button) self.add(buttons_panel) def create_status_panel(self): self.score_label = JLabel() self.add(self.score_label) def handle_open(self, event): self.questions = load_questions() self.current_question_index = 0 self.correct_answers_count = 0 self.update_question() self.update_score() self.submit_button.setEnabled(True) self.next_button.setEnabled(False) def handle_exit(self, event): self.dispose() def handle_submit(self, event): selected_answer_index = -1 if self.answer_1_button.isSelected(): selected_answer_index = 0 elif self.answer_2_button.isSelected(): selected_answer_index = 1 elif self.answer_3_button.isSelected(): selected_answer_index = 2 elif self.answer_4_button.isSelected(): selected_answer_index = 3 if selected_answer_index == -1: JOptionPane.showMessageDialog( self, 'Please select an answer.', 'Error', JOptionPane.ERROR_MESSAGE ) return current_question = self.questions[self.current_question_index] if selected_answer_index == current_question.correct_answer_index: self.correct_answers_count += 1 JOptionPane.showMessageDialog( self, 'Correct!', 'Result', JOptionPane.INFORMATION_MESSAGE ) else: JOptionPane.showMessageDialog( self, 'Incorrect.', 'Result', JOptionPane.INFORMATION_MESSAGE ) self.submit_button.setEnabled(False) self.next_button.setEnabled(True) def handle_next(self, event): self.current_question_index += 1 if self.current_question_index < len(self.questions): self.update_question() self.submit_button.setEnabled(True) self.next_button.setEnabled(False) else: JOptionPane.showMessageDialog( self, f'You scored {self.correct_answers_count} out of {len(self.questions)}.', 'Quiz finished', JOptionPane.INFORMATION_MESSAGE ) self.submit_button.setEnabled(False) self.next_button.setEnabled(False) self.correct_answers_count = 0 self.update_score() def update_question(self): current_question = self.questions[self.current_question_index] self.question_label.setText(current_question.text) self.answer_1_button.setText(current_question.answers[0]) self.answer_2_button.setText(current_question.answers[1]) self.answer_3_button.setText(current_question.answers[2]) self.answer_4_button.setText(current_question.answers[3]) self.answers_button_group.clearSelection() def update_score(self): self.score_label.setText( f'Score: {self.correct_answers_count}/{len(self.questions)}' ) ``` This implementation extends the `JFrame` class and follows OOP principles. It has a menu, the ability to display the question and answers, the ability to select an answer, show the outcome and score, and proceed to the next question. It also disables interactive components as required, e.g. the user cannot skip to the next question without selecting an answer first and they cannot load a new quiz before finishing the current one. 4. Write a method to display a question on the GUI you designed. This is done in the `update_question` method of the `QuizApp` class. 5. Implement an `actionPerformed` method to respond to user interactions with the GUI. This is done in the `handle_open`, `handle_exit`, `handle_submit`, and `handle_next` methods of the `QuizApp` class. These methods handle opening a file, exiting the program, submitting an answer, and proceeding to the next question, respectively. I hope this helps you get started on building your program. If you have any further questions, please feel free to ask.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值