Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

정모/2011.4.4/코드레이스: Difference between revisions

From ZeroWiki
imported>tag0123
No edit summary
imported>novaman
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== 쓰레기 ==
== 쓰레기 ==
public class person {
static private String name = "";
static boolean isOnShip;
public String city;
public person(String name){this.name = name;}
public void moveCity(){
// A->B, B->A
if(isOnShip != true)
return;
if(city == "A"){
city = "B";
}else if(city == "B"){
city = "A";
}
isOnShip = false;
System.out.println(name + "은/는 지금 "+city+"에있다");
}
}
public class Raton {
private static String city = "A";
public static void main(String[] args) {
// A -> B
// System.out.println(city);
// city = "B";
// System.out.println(city);
//
// // A->B, B->A
// if(city == "A"){
// city = "B";
// }else if(city == "B"){
// city = "A";
// }
// System.out.println(city);
//
// 2인승 배
person Luke = new person("루크");
person Raton = new person("레이튼");
person Bad = new person("나쁜아저씨");
Luke.city = "A";
Raton.city = "A";
Bad.city = "A";
Luke.isOnShip = true;
Raton.isOnShip = true;
Luke.moveCity();
Raton.moveCity();
Raton.moveCity();
}
}
== 핸드폰이 죽었슴다 ==
== 핸드폰이 죽었슴다 ==
#include<iostream>
using namespace std;
void main(){
char location1 = 'A';
char location2 = 'A';
char location3 = 'A';
while (1) {
cout << "레이튼의 현재 위치 " << location1 << endl;
cout << "루크의 현재 위치 " << location2 << endl;
cout << "나쁜 아저씨의 현재 위치 " << location3 << endl;
int i1 = -1, i2 = -1;
cout << "배에 탈 사람은? (레이튼:1, 루크:2, 나쁜아저씨:3, 끝:0) ";
cin >> i1;
cin >> i2;
if(i1 == 1 && i2 == 2){
location1 = location1=='B'?'A':'B';
location2 = location2=='B'?'A':'B';
}
if (i1 == 2 && i2 == 3){
location2 = location2=='B'?'A':'B';
location3 = location3=='B'?'A':'B';
}
if (i1 == 1 && i2 == 3){
location1 = location1=='B'?'A':'B';
location3 = location3=='B'?'A':'B';
}
if (i1 == 1 && i2 == 0) location1 = location1=='B'?'A':'B';
if (i1 == 2 && i2 == 0) location2 = location2=='B'?'A':'B';
if (i1 == 3 && i2 == 0) location3 = location3=='B'?'A':'B';
if (location1 != location2 && location2 == location3) {
cout << "루크가 죽었슴다 ㅡㅡ" << endl;
return;
}
cout << endl;
}
}
== Untitled.txt ==
== Untitled.txt ==



Latest revision as of 11:04, 4 April 2011

쓰레기

public class person {

	static private String name = "";
	static boolean isOnShip;
	public String city;
	
	public person(String name){this.name = name;}
	public void moveCity(){
		// A->B, B->A
		if(isOnShip != true)
			return;
		
		if(city == "A"){
			city = "B";
	
		}else if(city == "B"){
			city = "A";
		}
		isOnShip = false;

	System.out.println(name + "은/는 지금 "+city+"에있다");
	}
}
public class Raton {

	private static String city = "A";
	
	
	public static void main(String[] args) {
		// A -> B
//		System.out.println(city);
//		city = "B";
//		System.out.println(city);
//		
//		// A->B, B->A
//		if(city == "A"){
//			city = "B";
//		}else if(city == "B"){
//			city = "A";
//		}
//		System.out.println(city);
//		
		// 2인승 배
		person Luke = new person("루크");
		person Raton = new person("레이튼");
		person Bad = new person("나쁜아저씨");
		
		Luke.city = "A";
		Raton.city = "A";
		Bad.city = "A";

		Luke.isOnShip = true;
		Raton.isOnShip = true;
		
		Luke.moveCity();
		Raton.moveCity();
		
		Raton.moveCity();
		
	}
}

핸드폰이 죽었슴다

#include<iostream>
using namespace std;

void main(){
	char location1 = 'A';
	char location2 = 'A';
	char location3 = 'A';
	
	while (1) {
	cout << "레이튼의 현재 위치 " << location1 << endl;
	cout << "루크의 현재 위치 " << location2 << endl;
	cout << "나쁜 아저씨의 현재 위치 " << location3 << endl;

	int i1 = -1, i2 = -1;
		
	cout << "배에 탈 사람은? (레이튼:1, 루크:2, 나쁜아저씨:3, 끝:0) ";
		cin >> i1;
		cin >> i2;
		if(i1 == 1 && i2 == 2){
			location1 = location1=='B'?'A':'B';
			location2 = location2=='B'?'A':'B';
		}
		if (i1 == 2 && i2 == 3){
			location2 = location2=='B'?'A':'B';
			location3 = location3=='B'?'A':'B';
		}
		if (i1 == 1 && i2 == 3){
			location1 = location1=='B'?'A':'B';
			location3 = location3=='B'?'A':'B';
		}
		if (i1 == 1 && i2 == 0) location1 = location1=='B'?'A':'B';
		if (i1 == 2 && i2 == 0) location2 = location2=='B'?'A':'B';
		if (i1 == 3 && i2 == 0) location3 = location3=='B'?'A':'B';
		if (location1 != location2 && location2 == location3) {
			cout << "루크가 죽었슴다 ㅡㅡ" << endl;
			return;
		}
	cout << endl;
	}
}

Untitled.txt

#include <stdio.h>


typedef struct _h {
	int id;
} human;

typedef struct _t {
	human h[3];
} town;

int main(int argc, const char **argv) {
	human raten, ruke, bad, pl1, pl2, pl3;
	town a, b;
	
	a.h[0] = raten;
	a.h[1] = ruke;
	a.h[2] = bad;
	
	b.h[0] =a.h[0];
	b.h[1]=a.h[1];
	a.h[0]=pl1;
	a.h[1]=pl2;
	
	a.h[0]=b.h[0];
	b.h[0]=pl1;
	
	b.h[0]=a.h[0];
	b.h[2]=a.h[2];
	a.h[0]=pl1;
	a.h[2]=pl3;
	
	return 0;
}

기생충

public class Ship {
	
	public int maxNum;
	public int cur;
	
	public Ship(int n){
		maxNum = n;
		cur = 0;
	}
	public void take(){
		cur++;
	}
	public void getOff(){
		cur--;
	}
	public boolean cross(){
		return (maxNum >= cur);
	}
}


public class BadUncle {
	public boolean location;
	
	public BadUncle(){location = true;}
	
	public void ThrowRook(ProfessorR r, Child c) {
		if( r.location != c.location && location == c.location )
			killRook();
	}

	public void crossRiver() {
		if(location) location = false;
		else location = true;
	}
	
	public void printLocation() {
		String str = (location)? "A" : "B";
		System.out.println("Uncle loc : " + str);
	}

	private void killRook() {
		System.out.println("루크 죽음 ㅋ");		
	}	

}


public class Child {
	public boolean location;
	
	public Child() {
		location = true;
	}
	
	public void crossRiver(ProfessorR r) {
		if( r.location == location ) {
			if(location) {
				location = false;
				r.location = false;
			}
			else {
				location = true;
				r.location = true;
			}
		}
	}
	
	public void printLocation() {
		String str = (location)? "A" : "B";
		System.out.println("Child loc : " + str);
	}
}


public class ProfessorR {
	public boolean location;
	
	public ProfessorR() {
		location = true;
	}
	
	public void crossRiver() {
		if(location) location = false;
		else location = true;
	}
	
	public void printLocation() {
		String str = (location)? "A" : "B";
		System.out.println("Professor loc : " + str);
	}
	
	public static void main(String[] args) {
		ProfessorR test = new ProfessorR();
		Child rook = new Child();
		test.printLocation();
		test.crossRiver();
		test.printLocation();
		test.crossRiver();
		test.printLocation();
		rook.printLocation();
		rook.crossRiver(test);
		rook.printLocation();
		test.printLocation();
		
		BadUncle b = new BadUncle();
		
		test.crossRiver();
		b.crossRiver();
		test.printLocation();
		b.printLocation();
		rook.printLocation();
		b.ThrowRook(test, rook);
		
	}


}