(双语版)少儿创意代码题目2:二维数组--萌“奇”小队

在一个万圣节的晚会🎇上所有人坐成ni行nj列,晚会中混入了有一群来自“萌“奇”小队🐥”的小淘气😋,就如名字一样,他们每个人身上穿着带有奇数号码的衣服。//万圣节有一句名言:不给糖🍭,就捣蛋!\\
为了让“萌“奇”小队”的小淘气不捣蛋,主持人🎤要给他们发糖。可“萌“奇”小队”的小淘气就是想淘气于是和主持人开始了“捉迷藏🙈”请你帮帮主持人找出“萌“奇”小队”的小淘气的坐标🗺️(X行X列)再把坐标按照ni行nj列排成矩阵,让主持人精准投放“糖衣炮弹💘”,打破“萌“奇”小队”的小淘气的“阴谋”😭。

输入格式:
第一行输入整数ni、nj。
后nj行每行输入ni个整数。
输出格式:
每行输出ni个坐标,末尾加\。
输入样例(“()”=注释):
4(ni➡️行) 3(nj➡️列)
1 2 3 4
5 6 7 8
9 10 11 12
输出样例:
1行1列、2行1列、3行1列 \
1行3列、2行3列、3行3列 \

At a Halloween party 🎇, everyone is seated in ni rows and nj columns. During the party, there were some mischievous kids from the "Cute 'Odd' Squad" 🐥 who, as their name implies, wore clothes with odd numbers on them. // There's a famous saying during Halloween: Trick or treat! \ To prevent the "Cute 'Odd' Squad" kids from causing trouble, the host 🎤 decided to give them candies. However, the mischievous kids from the "Cute 'Odd' Squad" wanted to play hide-and-seek 🙈 with the host. Please help the host find the coordinates 🗺️ (X row X column) of the "Cute 'Odd' Squad" kids and arrange these coordinates into a matrix of ni rows and nj columns so that the host can precisely deliver the "candy bombs" 💘 and thwart the kids' mischief plans 😭.

Input format: The first line contains two integers ni (rows), nj (columns). Each of the following nj lines contains ni integers. Output format: For each row, output ni coordinates, ending with a backslash .

Sample input (comments in parentheses): 4 (ni → rows) 3 (nj → columns)

1 2 3 4

5 6 7 8

9 10 11 12

Sample output:

1r1c、2r1c、3r1c \
1r3c、2r3c、3r3c \

答案样例(多种方法本题使用数组)

#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int a[10][10],c,ni,nj,f=0;
    cin >>nj>>ni;
    for (int i=0;i<ni;i++)
    {
        for (int j=0;j<nj;j++)
	{
	    cin >>c;
	    a[i][j]=c;
	}
    }
    for (int j=0;j<nj;j++)
    {
        f=0;
	for (int i=0;i<ni;i++)
	{
	    if (a[i][j]%2!=0)
    	    {
		cout <<i+1<<"行"<<j+1<<"列"<<"、"; 
		f+=1;
	    }
	}
        if (f==ni)
        {
    	printf ("\b \b");
    	cout <<"\\\n";
        }
    }
	return 0;
 }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值