標題:
APCS 實作題 10602 - 1
[打印本頁]
作者:
ray
時間:
2020-5-3 14:58
標題:
APCS 實作題 10602 - 1
https://zerojudge.tw/ShowProblem?problemid=c461
作者:
張健勳
時間:
2020-5-3 15:18
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
bool im = true;
if (a != 0)
a = 1;
if (b != 0)
b = 1;
if (c != 0)
c = 1;
if ((a & b) == c)
{
cout << "AND" << endl;
im = false;
}
if ((a | b) == c)
{
cout << "OR" << endl;
im = false;
}
if ((a ^ b) == c)
{
cout << "XOR" << endl;
im = false;
}
if (im)
{
cout << "IMPOSSIBLE" << endl;
}
return 0;
system("PAUSE");
}
複製代碼
作者:
陳思惟
時間:
2020-5-3 15:29
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
//cout<<"Please input a b and 1/0 :";
cin>>a>>b>>c;
bool impossible=true;
if(a)
a=1;
if(b)
b=1;
if((a&b) == c){
cout<<"AND"<<endl;
impossible=false;
}
if((a|b) == c){
cout<<"OR"<<endl;
impossible=false;
}
if((a^b) == c){
cout<<"XOR"<<endl;
impossible=false;
}
if(impossible)
cout<<"IMPOSSIBLE"<<endl;
return 0;
}
複製代碼
作者:
陳泓瑜
時間:
2020-5-3 15:30
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b, c, n = 0;
scanf("%d %d %d", &a, &b, &c);
if(a != 0)
a = 1;
if(b != 0)
b = 1;
if(c != 0)
c = 1;
if((a & b) == c)
{
printf("AND\n");
n++;
}
if((a | b) == c)
{
printf("OR\n");
n++;
}
if((a ^ b) == c)
{
printf("XOR\n");
n++;
}
if(n == 0)
printf("IMPOSSIBLE");
system("pause");
return 0;
}
複製代碼
作者:
ray
時間:
2020-5-3 15:53
import java.io.*;
import java.util.Arrays;
public class C461 {
C461(){
StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
try
{
while(cin.nextToken() != StreamTokenizer.TT_EOF)
{
int ai = (int) cin.nval;
cin.nextToken();
int bi = (int) cin.nval;
cin.nextToken();
int ci = (int) cin.nval;
cin.nextToken();
boolean a = ai>0?true:false;
boolean b = bi>0?true:false;
boolean c = ci>0?true:false;
// do
int d = 0;
if((a & b) == c)
{
out.println("AND");
d++;
}
if((a | b) == c)
{
out.println("OR");
d++;
}
if((a ^ b) == c)
{
out.println("XOR");
d++;
}
if(d == 0)
out.println("IMPOSSIBLE");
out.flush();
}
}catch(Exception e)
{
out.println(e.toString());
out.flush();
}
}
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
new C461();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2