金子数量——c++

金子数量

Description

某地区有n条(编号依次为1到n)互不交叉的道路,每条道路上都有m个数字,其中能被8整除的数称为金子数,这个数字表示其重量。

如下表是3条道路,每条道路中有5个数的一种可能情况。

苏海想在n条道路中走一条金子重量之和最大的道路,请编程帮他找出这条道路吧

Input

输入共 n+1行。

第1行两个整数 n和 m,表示总共有 n条道路,每条道路上有 m个数。

接下来 n行,每行 m个正整数。

Output

一个整数,表示金子重量之和最大的道路编号。

Sample Input 1 

3 5
13 24 17 8 23
1 2 3 4 5
16 2 16 4 8

Sample Output 1

3

Source

2016年慈溪市小学生计算机程序设计竞赛复赛

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int arr[n][m];//n行m列
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>arr[i][j];
		}
	}
	int sum[n]={0};//金子重量
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(arr[i][j]%8==0){
				sum[i]+=arr[i][j];
			}
		}
	}
	int max=sum[0];
	int add;
	for(int i=0;i<n;i++){
		if(sum[i]>max){
			add=i;
			max=sum[i];
		}
	}
	cout<<add+1;
	return 0;
}

 水~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个简单的黄金矿工游戏的多文件 C++ 实现代码,使用了 EasyX 图形库。具体实现方法如下: 1. 创建一个 `main.cpp` 文件,用于包含主函和游戏循环逻辑。 ```c++ #include "Game.h" #include <graphics.h> int main() { initgraph(800, 600); // 初始化图形界面 Game game; // 创建游戏对象 game.start(); // 启动游戏循环 closegraph(); // 关闭图形界面 return 0; } ``` 2. 创建一个 `Game.h` 文件,用于定义游戏类。 ```c++ #ifndef GAME_H #define GAME_H #include "Map.h" #include "Player.h" class Game { public: Game(); void start(); private: Map map; Player player; }; #endif // GAME_H ``` 3. 创建一个 `Game.cpp` 文件,用于实现游戏类的方法。 ```c++ #include "Game.h" Game::Game() { map.init(); // 初始化地图 player.init(400, 500); // 初始化玩家 } void Game::start() { while (!map.isGameOver()) // 游戏循环 { map.draw(); // 绘制地图 player.draw(); // 绘制玩家 Sleep(10); // 延迟一段时间 cleardevice(); // 清空屏幕 } } ``` 4. 创建一个 `Map.h` 文件,用于定义地图类。 ```c++ #ifndef MAP_H #define MAP_H #include <vector> using namespace std; class Map { public: Map(); void init(); void draw(); bool isGameOver(); private: vector<vector<int>> mapData; int score; }; #endif // MAP_H ``` 5. 创建一个 `Map.cpp` 文件,用于实现地图类的方法。 ```c++ #include "Map.h" #include <graphics.h> #include <time.h> Map::Map() { score = 0; // 初始化分 } void Map::init() { srand(time(NULL)); // 设置随机种子 for (int i = 0; i < 20; i++) // 初始化地图据 { vector<int> row; for (int j = 0; j < 25; j++) { if (i == 0 || i == 19 || j == 0 || j == 24) { row.push_back(1); // 边界为石头 } else { row.push_back(rand() % 3); // 其他位置为金子、石头或空地 } } mapData.push_back(row); } } void Map::draw() { settextcolor(YELLOW); settextstyle(16, 0, _T("宋体")); outtextxy(10, 10, _T("得分:")); TCHAR scoreStr[32]; _stprintf_s(scoreStr, _T("%d"), score); outtextxy(70, 10, scoreStr); // 绘制分 for (int i = 0; i < 20; i++) { for (int j = 0; j < 25; j++) { if (mapData[i][j] == 1) { setfillcolor(BROWN); solidrectangle(j * 32, i * 32, j * 32 + 32, i * 32 + 32); // 绘制石头 } else if (mapData[i][j] == 2) { setfillcolor(YELLOW); solidcircle(j * 32 + 16, i * 32 + 16, 10); // 绘制金子 } } } } bool Map::isGameOver() { return false; // TODO: 实现游戏结束条件 } ``` 6. 创建一个 `Player.h` 文件,用于定义玩家类。 ```c++ #ifndef PLAYER_H #define PLAYER_H #include <graphics.h> class Player { public: Player(); void init(int x, int y); void draw(); private: int posX, posY; }; #endif // PLAYER_H ``` 7. 创建一个 `Player.cpp` 文件,用于实现玩家类的方法。 ```c++ #include "Player.h" Player::Player() { } void Player::init(int x, int y) { posX = x; posY = y; } void Player::draw() { setfillcolor(BLUE); solidcircle(posX, posY, 10); // 绘制玩家 } ``` 8. 最后,在项目中添加 EasyX 图形库的头文件和库文件,并编译运行即可。 注意:由于 EasyX 图形库只支持 Windows 系统,因此该代码只能在 Windows 系统下编译运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值