memset在此作用域尚未宣告 洛谷P1618 三連擊(升級版)
阿新 • • 發佈:2021-07-26
一開始程式碼中是不含有#include<string.h>,後面百度memset在此作用域尚未宣告,將標頭檔案 #include<string> 改為 #include<string.h>
另附題目連結 https://www.luogu.com.cn/problem/P1618
#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #include <string.h> using namespace std; intha[10]; void check1(int t) { ha[t / 100] = 1; ha[t / 10 % 10] = 1; ha[t % 10]=1; } bool check(int x, int y, int z) { /*for (int i = 1; i <= 9; i++) ha[i] = 0;*/ memset(ha, 0, sizeof(ha)); if (y > 999|| z>999) return 0; check1(x); check1(y); check1(z);for (int i = 1; i <= 9; i++) { if (ha[i] == 0) return 0; } return 1; } int main() { int A, B, C; int x, y, z; int sum = 0; cin >> A >> B >> C; for (int x = 123; x <= 987; x++) { if (x * B % A || x * C % A) continue; y = x * B / A; z = x * C / A; if (check(x, y, z)) { cout << x<<" " << y << " " << z << endl; sum++; } } if (sum == 0) cout << "No!!!" << endl; return 0; }
本文來自部落格園,作者:magicat,轉載請註明原文連結:https://www.cnblogs.com/magicat/p/15061019.html