第5个测试点RE求助...

P1618 三连击(升级版)

Arqiu @ 2019-03-23 09:56:30

...在本地可以输出正确答案呀...

#include <bits/stdc++.h>
using namespace std;

int main(){

    int a, b, c;    //三个三位数的比例是 a : b : c 
    int x, y, z;    //题目寻找的 3个三位数 
    int sum;        //统计 1~9出现的次数
    int flag = 0;   //flag值为 1表示有解
    int num[10];    //数组中值为 1,表示对应下标的数字出现过 

    cin >> a >> b >> c; 

    for(int i = 1; i <= 999; i++){
        //初始化
        memset(num, 0, sizeof(int)*10);
        sum = 0;
        //寻找所需的 3个三位数 
        x = a * i;
        num[x/100] = num[x/10%10] = num[x%10] = 1;
        y = b * i;
        num[y/100] = num[y/10%10] = num[y%10] = 1;
        z = c * i;
        num[z/100] = num[z/10%10] = num[z%10] = 1;
        //统计 1~9出现的次数 
        for(int n = 1; n <= 9; n++)
            sum += num[n];
        //如果 1~9都出现过 
        if(sum == 9){
            flag = 1;
            cout << x << " " << y << " " << z << endl; 
        }
    }
    //如果 1~9没有都出现过,那么没有满足条件的三个三位数 
    if(!flag)
        cout << "No!!!"; 

    return 0;
}

by 白菜道士 @ 2019-03-23 10:22:34

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){

    int a, b, c;
    int x, y, z;
    int sum;
    int flag = 0;
    int num[10];
    cin >> a >> b >> c; 
    for(int i = 1; i <= 999; i++){
        memset(num, 0, sizeof(int)*10);
        sum = 0;
        x = a * i;
        if(x>999)   continue;
        num[x/100] = num[x/10%10] = num[x%10] = 1;
        y = b * i;
        if(y>999)   continue;
        num[y/100] = num[y/10%10] = num[y%10] = 1;
        z = c * i;
        if(z>999)   continue;
        num[z/100] = num[z/10%10] = num[z%10] = 1;
        for(int n = 1; n <= 9; n++)
            sum += num[n];
        if(sum == 9){
            flag = 1;
            cout << x << " " << y << " " << z << endl; 
        }
    }
    if(!flag)
        cout << "No!!!"; 
    return 0;
}

防数组爆


by Arqiu @ 2019-03-23 12:39:06

@轩少 感谢大佬的防爆措施o(∩_∩)o! AC了!


|