A. Toy Cars

A. Toy Cars
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.

There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:

  •  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix.
  • 0: if no car turned over during the collision.
  • 1: if only the i-th car turned over during the collision.
  • 2: if only the j-th car turned over during the collision.
  • 3: if both cars turned over during the collision.

Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.

Each of the next n lines contains n space-separated integers that determine matrix A.

It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix.

It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.

Output

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

Sample test(s)
input
3
-1 0 0
0 -1 1
0 2 -1
output
2
1 3 
input
4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1
output
0

题意:n表示小车的数量,-1表示小车自己不会与自己相撞,1表示该行所表示的车号被撞坏,2表示该列所表示的车号被撞坏,3表示都被撞坏

法1:

#include<stdio.h>
#include<string.h>
int s[110][110], a[110], b[110], vis[110];

int main()
{
    int n, i, j;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            scanf("%d", &s[i][j]);
        }
    }
    memset(vis,0,sizeof(vis));
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++)
    {
        a[i]=i;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(s[i][j]==1)
            {
                vis[i]=1;
            }
            else if(s[i][j]==2)
            {
                vis[j]=1;
            }
            else if(s[i][j]==3)
            {
                vis[i]=vis[j]=1;
            }
        }
    }
    int t=0, sum=0;
    for(int i=0;i<n;i++)
    {
        if(vis[i]==0)
        {
            b[t++]=a[i];
            sum++;
        }
    }
    printf("%d\n", sum);
    if(sum!=0)
    {
        for(int i=0;i<t;i++)
        {
            printf("%d", b[i]+1);
            if(i<t-1)
                printf(" ");
        }
    }
    return 0;
}

法2

#include<stdio.h>
int main()
{
    int n;
    int s[110][110];
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            scanf("%d", &s[i][j]);
        }
    }
    int f;
    int a[110], t=0, sum=0;
    for(int i=0; i<n; i++)
    {
        f=1;
        for(int j=0; j<n; j++)
        {
            if(s[i][j]==1 || s[i][j]==3)
            {
                f=0;
                break;
            }
        }
        if(f==1)
        {

            a[t++]=i+1;

            sum++;
        }
    }
    printf("%d\n", sum);
    if(sum!=0)
    {
        for(int i=0; i<t; i++)
        {
            printf("%d", a[i]);
            if(i<t-1)
                printf(" ");
        }
    }
    return 0;
}

 

你写的全错 在看看要求: 在右侧编辑区补全函数 execute 中 Begin-End 区间的代码,根据参数opcode对应的指令操作码、op1、op2对应的 2 个操作数,结合上图对指令功能的描述编程模拟实现 CPU 指令执行及写结果的操作。其中,参数 reg、mem、pReg分别表示通用寄存器、主存和程序计数器。execute 函数的返回值规定如下:若操作码是add、sub、mul、div、mov1、mov2、mov3、in、out,则返回第 1 个操作数对应位置存放的值;若操作码是jmp、jz,返回程序计数器中的值;若操作码是halt,返回False。   说明: 本关 execute函数中,opcode,op1, op2的参数值来自于第 4 关指令译码函数decode执行后得到的元组(opcode,op1, op2)。 本关主要内容为指令执行过程的编程实现,待执行的指令已经由评测文件放入指令寄存器。 本关待执行的指令所在文件 .toy 被评测文件装入主存时,统一从主存地址000开始存放,即指令在程序中的逻辑地址(.toy 文件中指令前面的编号)和其被装入主存后的物理地址一致。 测试说明   平台将使用测试集运行你编写的程序代码,若全部的运行结果正确,则通关。   本关卡共有 5 个测试集,测试集输入数据主要分为 2 个部分,第 1 部分是使用 TOY 计算机指令集编写的测试代码文件,分别命名为 test1.toy ~ test5.toy,这些代码文件主要用于测试各种指令是否能够正确执行,故不考虑代码的完整性和功能性;第 2 部分是测试代码需要的输入数据,若程序代码中无in输入指令,则缺省第 2 部分的输入数据。   测试样例如下所示。   测试输入:test1.toy   预期输出:10   测试输入:test5.toy 10   预期输出:40   test1.toy ~ test5.toy 的测试代码如下所示。 #test1.toy 000 mov3 0 1 001 mov3 1 11 002 sub 1 0 003 mov2 2 1 #test2.toy 000 mov3 3 10 001 mov3 4 3 002 div 3 4 003 add 4 4 004 jz 3 002 005 out 3 #test3.toy 000 mov3 1 22 001 mov2 0 1 002 mov1 0 0 #test4.toy 000 mov3 0 4 001 jmp 003 002 mov2 990 0 003 halt #test5.toy 000 mov3 8 4 001 in 9 002 mul 8 9
11-29
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值