[ create a new paste ] login | about

Link: http://codepad.org/1BjRA5aY    [ raw code | fork ]

hieunv1996 - C++, pasted on Mar 9:
#include <iostream>
#include <conio.h>
using namespace std;
 

int x, y;
int vx, vy;
int z;
 
int luat1();
int luat2();
int luat3();
 
int main()
{
    vx = 4,vy = 3,z = 2;
        x = 0;
        y = 0;
        while (x != z)
        {
            luat1();
            luat2();
            luat3();
        }
}
int luat1()
{
    if (x == vx) // Neu binh x day
    {
        x = 0;
        cout << "Luat L1 -> x = " << x << ", y = " << y << endl;
        return 1;
    }
    return 0;
}
int luat2()
{
    if (y == 0) // Neu binh y trong
    {
        y = vy;
        cout << "Luat L2 -> x = " << x << ", y = " << y << endl;
        return 1;
    }
    return 0;
}
int luat3()
{
    if (x < vx && y > 0)// Neu x < maxX va binh y co nuoc
    {
        if (y > vx - x) // Neu nuoc binh y dang co nhieu hon so nuoc binh x co the chua them. 
        {
            y -= vx - x;  // binh y bi mat luong nuoc do sang x
            x = vx; // binh x day
        }
        else //Neu x du chua toan bo nuoc cua y
        {
            x += y; // x lay het nuoc cua y
            y = 0; // binh y trong
        }
        cout << "Luat L3 -> x = " << x << ", y = " << y << endl;
        return 1;
    }
    return 0;
}


Create a new paste based on this one


Comments: