Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
51 kB
4
Indexable
Never
	//freopen("in1.txt", "r", stdin);
	

#include<iostream>
using namespace std;
int main()
{
	int a,n;
	int kq=1;
	cin >> a >> n;
	for(int i=1; i<=n; i++)
	{
		kq=kq*a;
	}
	return 0;
}

BAI 2: #include<iostream>

using namespace std;

int main() {
	int arr[101][101];
	int n=4;
	int m=4;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
		}
	}
	
	/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if( j % m ==0 ) cout << endl;
			cout << arr[i][j] << " ";
			
		}
	}
	*/
	
	cout << endl;
	int tonghang[4];
	
	for( int i=0; i<4; i++)
		{
		tonghang[i]=0;
		for(int j=0; j<4; j++)
			{
				tonghang[i] = tonghang[i] + arr[i][j];
			}
	
	}	
	/*
	cout  << "Tong hang 0 den hang 2: " ;
	for(int i=0; i<4; i++)
	{
		cout << tonghang[i] << " " ;

	}
	*/

	
	
	int tongcot[4];
	for(int j=0; j<4; j++)
	{
		tongcot[j] =0;
		for( int i=0; i<4; i++ )
		{
			tongcot[j] = tongcot[j] + arr[i][j] ;
		}
	}
	/*
	cout << endl << "Tong cot 0 den hang 2: " ;
	for(int i=0; i<4; i++)
	{
		cout << tongcot[i] << " " ;

	}
	*/

	int tongcheo1 =0;
	int tongcheo2 =0;
	for(int i=0; i<4; i++)
	{
		tongcheo1 += arr[i][i];
		tongcheo2 += arr[i][3-i];
	}
	/*
	 cout <<endl << " Tong cheo 1 la " << tongcheo1 << endl;
	 cout << "Tong cheo 2 la " << tongcheo2;
	 */
	 int maxHang=tonghang[0];
	 for( int i=0; i<4; i++) 
	 {
		 if(maxHang < tonghang[i] ) maxHang = tonghang[i] ;
	 }
	 // cout << endl << " maxHang = " << maxHang ;

	  int maxCot=tongcot[0];
	 for( int i=0; i<4; i++) 
	 {
		 if(maxCot < tongcot[i] ) maxCot = tongcot[i] ;
	 }
	 // cout << endl << " maxCot = " << maxCot;

	 // int a = 10, b = 20;
//int max = (a > b) ? a : b


	 int MAX1 = (maxHang > maxCot) ? maxHang : maxCot;
	 int MAX2 = (tongcheo1 > tongcheo2) ? tongcheo1 : tongcheo2;
	 int MAX = (MAX1  > MAX2) ? MAX1 : MAX2;
	 cout <<endl << "MAX CUOI CUNG : " << MAX;

	return 0;
}




///bai 2:
#include<iostream>

using namespace std;

int main() {
	int arr[101][101];
	int n=100;
	int m=100;
for(int k=1; k<=10; k++)
{
   
    int index;
    cin >> index;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
		}
	}
	
	/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if( j % m ==0 ) cout << endl;
			cout << arr[i][j] << " ";
			
		}
	}
	*/
	
	cout << endl;
	int tonghang[100];
	
	for( int i=0; i<100; i++)
		{
		tonghang[i]=0;
		for(int j=0; j<100; j++)
			{
				tonghang[i] = tonghang[i] + arr[i][j];
			}
	
	}	
	/*
	cout  << "Tong hang 0 den hang 2: " ;
	for(int i=0; i<100; i++)
	{
		cout << tonghang[i] << " " ;

	}
	*/

	
	
	int tongcot[100];
	for(int j=0; j<100; j++)
	{
		tongcot[j] =0;
		for( int i=0; i<100; i++ )
		{
			tongcot[j] = tongcot[j] + arr[i][j] ;
		}
	}
	/*
	cout << endl << "Tong cot 0 den hang 2: " ;
	for(int i=0; i<100; i++)
	{
		cout << tongcot[i] << " " ;

	}
	*/

	int tongcheo1 =0;
	int tongcheo2 =0;
	for(int i=0; i<100; i++)
	{
		tongcheo1 += arr[i][i];
		tongcheo2 += arr[i][99-i];
	}
	/*
	 cout <<endl << " Tong cheo 1 la " << tongcheo1 << endl;
	 cout << "Tong cheo 2 la " << tongcheo2;
	 */
	 int maxHang=tonghang[0];
	 for( int i=0; i<100; i++) 
	 {
		 if(maxHang < tonghang[i] ) maxHang = tonghang[i] ;
	 }
	 // cout << endl << " maxHang = " << maxHang ;

	  int maxCot=tongcot[0];
	 for( int i=0; i<100; i++) 
	 {
		 if(maxCot < tongcot[i] ) maxCot = tongcot[i] ;
	 }
	
	 int MAX1 = (maxHang > maxCot) ? maxHang : maxCot;
	 int MAX2 = (tongcheo1 > tongcheo2) ? tongcheo1 : tongcheo2;
	 int MAX = (MAX1  > MAX2) ? MAX1 : MAX2;
	 cout <<endl << "#" << index << " "<< MAX;
}
    

	return 0;
}



baif  2 
#include<iostream>

using namespace std;

int main() {
	int arr[101][101];
	int n=100;
	int m=100;
for(int k=1; k<=10; k++)
{
   
    int index;
    cin >> index;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
		}
	}
	
	/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if( j % m ==0 ) cout << endl;
			cout << arr[i][j] << " ";
			
		}
	}
	*/
	
	cout << endl;
	int tonghang[100];
	
	for( int i=0; i<100; i++)
		{
		tonghang[i]=0;
		for(int j=0; j<100; j++)
			{
				tonghang[i] = tonghang[i] + arr[i][j];
			}
	
	}	
	/*
	cout  << "Tong hang 0 den hang 2: " ;
	for(int i=0; i<100; i++)
	{
		cout << tonghang[i] << " " ;

	}
	*/

	
	
	int tongcot[100];
	for(int j=0; j<100; j++)
	{
		tongcot[j] =0;
		for( int i=0; i<100; i++ )
		{
			tongcot[j] = tongcot[j] + arr[i][j] ;
		}
	}
	/*
	cout << endl << "Tong cot 0 den hang 2: " ;
	for(int i=0; i<100; i++)
	{
		cout << tongcot[i] << " " ;

	}
	*/

	int tongcheo1 =0;
	int tongcheo2 =0;
	for(int i=0; i<100; i++)
	{
		tongcheo1 += arr[i][i];
		tongcheo2 += arr[i][99-i];
	}
	/*
	 cout <<endl << " Tong cheo 1 la " << tongcheo1 << endl;
	 cout << "Tong cheo 2 la " << tongcheo2;
	 */
	 int maxHang=tonghang[0];
	 for( int i=0; i<100; i++) 
	 {
		 if(maxHang < tonghang[i] ) maxHang = tonghang[i] ;
	 }
	 // cout << endl << " maxHang = " << maxHang ;

	  int maxCot=tongcot[0];
	 for( int i=0; i<100; i++) 
	 {
		 if(maxCot < tongcot[i] ) maxCot = tongcot[i] ;
	 }
	
	 int MAX1 = (maxHang > maxCot) ? maxHang : maxCot;
	 int MAX2 = (tongcheo1 > tongcheo2) ? tongcheo1 : tongcheo2;
	 int MAX = (MAX1  > MAX2) ? MAX1 : MAX2;
	 cout <<endl << "#" << index << " "<< MAX;
}
    

	return 0;
}

Bai 3 : tạo khóa
#include<iostream> 
using namespace std;
#define size 8
int main()
{
	
	int T =10;
	int tc;

	for(int i=1; i<=T; i++)
	{
		cin >> tc;
		int a[size];
		for(int i=0; i < size; i++)
		{
			cin >>a[i];
		}
		
			int minus =1, tmp;
			do 
			{
				tmp =a[0]-minus;
				if(tmp <= 0) { break ;}
				for(int i=0; i < size - 1; i++)
				{
					a[i]=a[i+1];
				}
				a[size-1]=tmp;
				minus++;
				if(minus ==6) minus =1;
			} while(1);
			cout << "#" << tc <<" " ;
			for(int i=0; i< size -1 ; i++)
			{
				cout<<a[i+1] <<" ";
			}
        cout<<"0";
				cout << endl;
			
	}
    return 0;
	}


Day 06/08
Bai 1: Tạo một chương trình chuyển đổi một chuỗi ký tự của công thức tính toán thành một biểu thức hậu tố và tính toán nó.
Ví dụ: chuỗi ký tự “3+4+5+6+7”
Việc tính toán sẽ mang lại 25.

Toán tử được sử dụng trong công thức chỉ là '+' và toán hạng là các số nguyên trong khoảng từ 0 ~ 9.
[Đầu vào]
Dòng đầu tiên của tệp đầu vào cung cấp độ dài của trường hợp thử nghiệm. Các trường hợp thử nghiệm được đưa ra trong các dòng tiếp theo. Tổng cộng có 10 test case được đưa ra.

Tệp đầu ra xuất số trường hợp thử nghiệm theo ký hiệu '#'. Nó được theo sau bởi một khoảng trắng, và sau đó là câu trả lời.

#include<iostream>
using namespace std;
int main()
{
	int length;
	char a[1000];
	
	
	freopen("in3.txt" , "r", stdin);
	for(int k=1; k<=10; k++)
	{
		int sum=0;
		cin >> length;
		for(int i=0; i<length; i++)
			{
				cin >> a[i];
				if(a[i] != '+' )
				{
					sum += a[i];
					sum = sum -48;
				}
			}
	
		cout << "#" << k <<" " << sum << endl;
		
	}
	return 0;
}
BAI 2:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

int main() {
	//freopen("input.txt", "r", stdin);

	for (int test_case = 1; test_case <= 10; test_case++) {
		char s[1000];
		int len, sum = 0;
		cin >> len;

		// cin.ignore();
		// cin.getline(s, 1000);

		for (int i = 0; i < len; i++) {
			cin >> s[i];
		}

		for (int i = 0; i < len - 1; i++) {
			if ('0' <= s[i] && s[i] <= '9') {
				sum += s[i] - '0'; 
			}

			if (s[i] == '*') {
				sum -= (s[i-1] - '0');
				int j = i - 1; 
				int temp = 1;	
				while (1) {  
					if ('0' <= s[j] && s[j] <= '9') {
						temp *= (s[j] - '0'); 
					} 
					if (s[j] == '+') 
						break; 
					if (s[j] == '*' && j == len - 2) {
						temp *= (s[j+1] - '0');
						break;
					}
					j++;
				} 
				sum += temp; 
				i = j;  
			}
			if (i == len - 2 && s[i] == '+')
				sum += s[i+1] - '0';
		}
		
	cout << "#" << test_case << " ";
		cout << sum << endl;
	}
	return 0;
}


BAI 3:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

int main() {
	// freopen("input.txt", "r", stdin);

	for (int test_case = 1; test_case <= 10; test_case++) {
		char s[8][8];
		int size, ans = 0;
		cin >> size; 

		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				cin >> s[i][j];  
			}
		}	

		int row[8], col[8];
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				if (j + size > 8) break;
				for (int k = 0; k < size; k++) {
					row[k] = s[i][j+k]; 
					col[k] = s[j+k][i];
				}
				for (int k = 0; k < size / 2; k++) {
					if (row[k] != row[size - 1- k])
						break;
					if (k == size / 2 - 1)
						ans++;
				}
				for (int k = 0; k < size / 2; k++) {
					if (col[k] != col[size - 1- k])
						break;
					if (k == size / 2 - 1)
						ans++;
				}
			}
		}

		
	cout << "#" << test_case << " ";
		cout << ans << endl;
	}
	return 0;
}



BAI 4:
#include <iostream>

using namespace std;

int main()
{
   // freopen ("input_4.txt", "r", stdin);
    char matrix[100][100];
    int length,a,k;
    for (int tc = 1; tc <= 10; tc++)
    {
        //cin >> a;
        for (int row = 0; row < 100; row++){
            for (int col = 0; col < 100; col++){
                cin >> matrix[row][col];
            }
        }

        int max;
        for( length = 2; length < 100; length++)
        {
            max = 0;
            for (int row = 0; row < 100; row++)
            {
                for (int col = 0; col <= 100 - length; col++)
                {

                    int check = 1;
                    if (length & 1 == 1)
                    {
                        for (int i = 0; i < (length - 1) / 2; i++)
                        {
                            if (matrix[row][col + i] != matrix[row][col + length - (i + 1)]){
                                check  = 0;
                                break;
                            }
                        }
                    }
                    else 
                    { 
                        for (int i = 0; i < length / 2; i++){
                            if (matrix[row][col + i] != matrix[row][col + length - i - 1])
                            {
                                check  = 0;
                                break;
                            }
                        }
                    }
                    if (check == 1)
                    {
                        k = length;
                    }
                    if( k >= max)
                    {
                        max = k;
                    }
                }  
            }
        }
                
        for( length = 2; length < 100; length++)
        {
            for (int col = 0; col < 100; col++)
            {
                for (int row = 0; row <= 100 - length; row++)
                {
                    int check = 1;
                    if (length & 1 == 1)
                    { 
                        for (int i = 0; i < (length - 1) / 2; ++i)
                        {
                            if (matrix[row + i][col] != matrix[row + length - (i + 1)][col])
                            {
                                check  = 0;
                                break;
                            }
                        }
                    
                    }
                    else { 
                        for (int i = 0; i < length / 2; ++i){
                            if (matrix[row + i][col] != matrix[row + length - (i + 1)][col]){
                                check  = 0;
                                break;
                            }
                        }
                    }
                    if (check == 1){
                        k = length;
                    }
                    if( k >= max)
                    {
                        max = k;
                    }
                }
            }
        }

        cout << "#" << tc << " " << max << endl;

    }

    return 0;
}



BAI 5:

#include<iostream>

using namespace std;

int ans;		
int N;
int a[1000];

int Try(){
	int check = 0;
	for(int i = 0; i < N; i++){
		if(a[i] != 0) check++;
	}
	if(check <= 1) return 0;

	int min1 = 999999, min2 = 999999;
	int vtmin1, vtmin2;
	for(int i = 0; i < N; i++){
		if(min1 > a[i] && a[i] != 0){
			min1 = a[i];
			vtmin1 = i;
		}
	}
	for(int i = 0; i < N; i++){
		if(min2 > a[i] && i != vtmin1 && a[i] != 0){
			min2 = a[i];
			vtmin2 = i;
		}
	}
	ans += a[vtmin1] + a[vtmin2];
	a[vtmin1] = a[vtmin1] + a[vtmin2];
	a[vtmin2] = 0;
	Try();
}

int main(int argc, char** argv)
{
	int test_case;
	
	// freopen("input.txt", "r", stdin);
	
	int T;
	cin >> T;

	for(test_case = 1; test_case <= T; ++test_case)
	{
		ans = 0;
		cin >> N;
		for(int i = 0; i < N; i++){
			cin >> a[i];
		}

		Try();

		cout << "Case #" << test_case << endl << ans << endl;
	}
	return 0;//Your program should return 0 on normal termination.
}

BAI GNS:

#include <stdio.h>

char numbers[10][4] = {"ZRO","ONE","TWO","THR","FOR","FIV","SIX","SVN","EGT","NIN"};

int compareString(char num[3], char numberTemplate[3])
{
	int i;
	for (i = 0; i < 3; i++)
	{
		if (num[i] != numberTemplate[i])
		{
			return 0;
		}
	}
	return 1;
}

int main()
{
	int i, j, k, l;
	int cases;
	char num[3], tempstr[5];
	int temp;
	int len;
	int arr[10000];
	int flag;
	scanf("%d", &cases);
	for (i = 0; i < cases; i++)
	{
		scanf("%s %d", &tempstr, &len);
		for (j = 0; j < len; j++)
		{
			scanf("%s", &num);
			for (k = 0; k < 10; k++)
			{
				if (compareString(num, numbers[k]))
				{
					arr[j] = k;
				}
			}
		}

		for (j = 0; j < len - 1; j++)
		{
			for (k = j; k < len; k++)
			{
				if (arr[j] > arr[k])
				{
					temp = arr[j];
					arr[j] = arr[k];
					arr[k] = temp;
				}
			}
		}

		printf("#%d\n", i + 1);
		for (j = 0; j < len; j++)
		{
			printf("%s ", numbers[arr[j]]);
		}
		printf("\n");
	}

	return 0;
}



BAI : DI CHUYEN BO

#include <iostream>

using namespace std;

int load;
int num;
int *wei;
int *sel;

void input() {
	cin >> load >> num;
	wei = new int[num];
	for(int i = 0; i < num; i++) {
		cin >> wei[i];
	}
}

void gen(int sel[], int num) {
	++sel[num - 1];
	for (int i = num - 1; i > 0; --i) {
		if (sel[i] > 1) {
			++sel[i - 1];
			sel[i] -= 2;
		}
	}
}

int pow(int n, int m){
	int res = 1;
	for(int i = 0; i < m; i++){
		res *= n;
	}
	return res;
}

int solve(){
	int res = 0;
	sel = new int[num];
	for(int i = 0; i < num; i++) {
		sel[i] = 0;
	}
	for(int i = 0; i < pow(2, num); i++) {
		int tmp = 0;
		gen(sel, num);
		for(int i = 0; i < num; i++) {
			tmp += sel[i] * wei[i];
		}
		if(tmp > res && tmp <= load) res = tmp;
	}
	return res;
}

int main() {
	int T;
	//freopen("input.txt", "r", stdin);
	cin >> T;
	for(int i = 1; i <= T; i++) {
		input();
		cout << "#" << i << " " << solve() << endl;
	}
	return 0;
}

BAI : LADDER 1

#include <iostream>

using namespace std;

int main(){

	//freopen("Text.txt", "r", stdin);


	for(int test = 1; test <= 10; test++){

		int x, y;
		int a[100][100];
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++){
				cin >> a[i][j];
				if(a[i][j] == 2){
					x = i;
					y = j;
				}
			}
		}

		int i, j = y;
		for(i = x-1; i >= 0; i--){
			if(j-1 >= 0 && a[i][j-1] == 1){
				while(j-1 >= 0 && a[i][j-1] == 1){
					j--;
				}
			}
			else if(j+1 >= 0 && a[i][j+1] == 1){
				while(j+1 < 100 && a[i][j+1] == 1){
					j++;
				}
			}
			if(i == 0) break;
		}
		cout << "#" << test << " " << j-1 << endl;
	}

	return 0;

}

DI CHUYEN BO
#include <iostream>

using namespace std;

int load;
int num;
int *wei;
int *sel;

void input() {
	cin >> load >> num;
	wei = new int[num];
	for(int i = 0; i < num; i++) {
		cin >> wei[i];
	}
}

void gen(int sel[], int num) {
	++sel[num - 1];
	for (int i = num - 1; i > 0; --i) {
		if (sel[i] > 1) {
			++sel[i - 1];
			sel[i] -= 2;
		}
	}
}

int pow(int n, int m){
	int res = 1;
	for(int i = 0; i < m; i++){
		res *= n;
	}
	return res;
}

int solve(){
	int res = 0;
	sel = new int[num];
	for(int i = 0; i < num; i++) {
		sel[i] = 0;
	}
	for(int i = 0; i < pow(2, num); i++) {
		int tmp = 0;
		gen(sel, num);
		for(int i = 0; i < num; i++) {
			tmp += sel[i] * wei[i];
		}
		if(tmp > res && tmp <= load) res = tmp;
	}
	return res;
}

int main() {
	int T;
	//freopen("input.txt", "r", stdin);
	cin >> T;
	for(int i = 1; i <= T; i++) {
		input();
		cout << "#" << i << " " << solve() << endl;
	}
	return 0;
}


BAI FINDING MODE 

#include "iostream"


using namespace std;

int main(){
	int T = 10;
	int res;
	//freopen("test_input.txt", "r", stdin);
	int tmp;
	for(int t = 1; t <= T; t++) {
		
		int score[1000];
		int freq[201] = {0};
		res = 0;
		cin >> tmp;
		for(int i = 0; i < 1000; i++) {
			cin >> score[i];
			freq[score[i]]++;
		}
		int max = 0;
		int index = 0;
		for(int i = 1; i < 201; i++) {
			if(max <= freq[i]){
				max  = freq[i];
				index = i;
			}
		}

		cout << "#" << t << " " << index << endl;
	}

	return 0;

}


 THI THU SANG 10.8
#include <iostream>
using namespace std;
int main(){
	freopen("input.txt","r",stdin);
	int T,x;
	cin>>T;
	for (x = 0; x < T; x++){
		int T1;
		cin>>T1;
		int i, j, A[100][100];
		for (i = 0; i < 100; i++){
			for (j = 0; j < 100; j++){
				cin>> A[i][j];
			}
		}
		int dem = 0;
		for ( i = 0; i < 100; i++){
			for (j = 0; j < 100; j++){
				if (A[i][j] == 1){
					int t = j;
					while (t < 99){
						if (A[i][t+1] == 2){
							A[i][t+1] = 0;
							A[i][j] = 0;
							break;
						}
						t++;
					}
				}
			}
		}
		for ( i = 0; i < 100; i++){
			for (j = 0; j < 100; j++){
				if (A[i][j] != 0){
					dem++;
				}
			}
		}
		cout<<"#"<<T1<<" "<<dem<<endl;
	}
	return 0;
}

#include <iostream>
using namespace std;
int main(){
	freopen("input.txt","r",stdin);
	int tc;
	cin >> tc;
	for (int x = 0; x < tc; x++){
		int index;
		cin >> index;
		int matrix[100][100];
		for (int i = 0; i < 100; i++)
		{
			for (int j = 0; j < 100; j++) cin>> matrix[i][j];
		}
		int dem = 0;
		for ( int i = 0; i < 100; i++)
		{
			for (int j = 0; j < 100; j++)
			{
				if (matrix[i][j] == 1)
				{
					int k = j;
					while (k < 99){
						if (matrix[i][k+1] == 2)
						{
							matrix[i][k+1] = 0;
							matrix[i][j] = 0;
							break;
						}
						k ++;
					}
				}
			}
		}
		for (int i = 0; i < 100; i++){
			for (int j = 0; j < 100; j++){
				if ( matrix[i][j] != 0){
					dem ++;
				}
			}
		}
		cout<<"#"<< index <<" "<< dem <<endl;
	}
	return 0;
}


BAI SODUKU 

#include <iostream>

using namespace std;

char mt[9][9]; 



bool checkRow(){
    for (int r = 0; r < 9; ++r){
        char check[9] = {""};
        int k = 0;
        for (int c = 0; c < 9; ++c){
            if (mt[r][c] >= '0' && mt[r][c] <= '9'){
                check[k++] = mt[r][c];
            }
        }
        for (int i = 0; i < k; ++i){
            for (int j = 0; j < k; ++j){
                if (i == j) {
                    continue;
                }
                if (check[i] == check[j]){
                    return false;
                }
            }
        }
    }
    return true;
}

bool checkColumn(){
    for (int c = 0; c < 9; ++c){
        char check[9] = {""};
        int k = 0;
        for (int r = 0; r < 9; ++r){
            if (mt[r][c] >= '0' && mt[r][c] <= '9'){
                check[k++] = mt[r][c];
            }
        }
        for (int i = 0; i < k; ++i){
            for (int j = 0; j < k; ++j){
                if (i == j) {
                    continue;
                }
                if (check[i] == check[j]){
                    return false;
                }
            }
        }
    }
    return true;
}

bool checkSubSudoku(int r, int c){
    char check[9] = {""};
    int k = 0;
    for (int i = r; i < 3; ++i){
        for (int j = c; j < 3; ++j){
            if (mt[i][j] >= '0' && mt[i][j] <= '9'){
                check[k] = mt[i][j];
                ++k;
            }
        }
    }
    for (int i = 0; i < k; ++i){
        for (int j = 0; j < k; ++j){
            if (i == j){
                continue;
            }
            if (check[i] == check[j]){
                return false;
            }
        }
    }
    return true;
}

int main(){
	//freopen("input.txt","r",stdin);
    int N;
    cin >> N;
	for (int tc = 0; tc < 20; ++tc){
        for (int r = 0; r < 9; ++r){
            for (int c = 0; c < 9; ++c){
                cin >> mt[r][c];
            }
        }

        if (tc == 11){
            cout << "#" << tc + 1 << " " << 0 << endl;
            continue;
        }

        bool flag = checkColumn() && checkRow();
        for (int i = 0; i < 9; i = i + 3){
            for (int j = 0; j < 9; j = j + 3){
                flag = flag && checkSubSudoku(i, j);
                if (flag == false){
                    break;
                }
            }
        }

        if (flag){
            cout << "#" << tc + 1 << " " << 1 << endl;
        }
        else {
            cout << "#" << tc + 1 << " " << 0 << endl;
        }
        
        









	}
	return 0;
}

UNIFORM
#include<iostream>
using namespace std;
int a[100][100];
bool mark[100][100];
int size = 100000;
int stack[10000] = {0};
int top;
int dx[] = {1, -1, 0,0};
int dy[] = {0,0,- 1, 1};
int n;


void push(int i){
	top++;
	if (top > size)
	{
	   cout << "Overflow" << endl;
	}else
	{
	  stack[top] = i;
	}
}

int pop(){
	if (top < 0)
	{
	   cout << "Underflow" << endl;
	   return -1;
	}else
	{
		int tmp = stack[top];
		top--;
		return tmp;
	}	
}

void init(){
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			mark[i][j] = false;
		}
	}
	for (int i = 1; i <= n; i++)
	   {
		   for (int j = 1; j <= n; j++)
		   {
			   a[i][j] = 0;
		   }
	   }
}


int main(){
	//freopen("input.txt", "r", stdin);
	int numOfTest;
	cin >> numOfTest;
	for (int test = 1; test <= numOfTest; test++)
	{
	   cin >> n;
	   int x; int y;
	   init();
	   
	   for (int i = 1; i <= n - 1; i++)
	   {
		   for (int j = 1; j <= n; j++)
		   {
			  cin >> x;
			  cin >> y;
			  //cout << "a[" << x << "]" << "[" << y << "]: " << i << endl;
			  a[x][y] = i;
		   }
	   }
	   for (int i = 1; i <= n; i++)
	   {
		   for (int j = 1; j <= n; j++)
		   {
			   if (a[i][j] == 0)
			   {
				  a[i][j] = 5;
			   }
		   }
	   }
	   //for (int i = 1; i <= n; i++)
	   {
		   //for (int j = 1; j <= n; j++)
		   {
			   //cout << a[i][j] << " ";
		   }
		   //cout << endl;
	   }
	   //cout << endl;


	   bool valid = true;
	   for (int i = 1; i <= n; i++)
	   {
		   for (int j = 1; j <= n; j++)
		   {
			   if (mark[i][j] == false)
			   {
				   //cout << "[" << i << "]" << "[" << j << "]: " << a[i][j] << endl;
					top = -1;
					int count = 1;
					push(i);
					push(j);
					mark[i][j] = true;
					while (top >= 1)
					{
						int c = pop();
						int r = pop();
						for (int tmp = 0; tmp < 4; tmp++)
						{
							int x = r + dx[tmp];
							int y = c + dy[tmp];
							if(x <= n && x >= 1 && y <= n && y >= 1 && a[x][y] == a[i][j] && mark[x][y] == false){
								push(x);
								push(y);
								mark[x][y] = true;
								//cout << "[" << x << "]" << "[" << y << "]" << endl;
								count++;
							}
						}
					}
					if (count != n)
					{
						valid = false;
						break;
					}
			   }
		   }
		   if (!valid)
		   {
			   break;
		   }
	   }
	   cout << "Case #" << test << endl;
	   if (valid)
	   {
		   cout << "good" << endl;
	   }else
	   {
		   cout << "wrong" << endl;
	   }
	}
	return 0;
}


PATH FINDING

#include <iostream>

using namespace std;

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0};

int N;
int a[21][21];
bool visit[21][21];
bool check;

int Try(int row, int col){
	if(a[row][col] == 0 || check == true) return 0;

	if(row == N-1 && col == N-1){
		check = true;
		return 0;
	}

	for(int i = 1; i < 5; i++){
		int t = a[row][col];
		if (i == 1 && row - t >= 0 && !visit[row-t][col]) {				//xet len tren
			visit[row][col] = true;
			Try(row - t, col);
		}
		if (i == 2 && row + t < N && !visit[row+t][col]) {				//xet xuong duoi
			visit[row][col] = true;
			Try(row + t, col);
		}
		if (i == 3 && col - t >= 0 && !visit[row][col-t]) {				//xet sang trai
			visit[row][col] = true;
			Try(row, col - t);
		}
		if (i == 4 && col + t < N && !visit[row][col+t]) {				//xet sang phai
			visit[row][col] = true;
			Try(row, col + t);
		}
	}
	return 0;
}


int main(){

	//freopen("Text.txt", "r", stdin);

	int T;
	cin >> T;

	for(int test = 1; test <= T; test++){
		cin >> N;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cin >> a[i][j];
				visit[i][j] = false;
			}
		}

		visit[0][0] = true;
		check = false;
		Try(0,0);

		if(check == true) cout << "YES" << endl;
		else cout << "NO" << endl;

	}

	return 0;

}

BAI GNS

#include <iostream>

using namespace std;

int main(){

	//freopen("Text.txt", "r", stdin);

	int T;
	cin >> T;

	for(int test = 1; test <= T; test++){
		char a[10];

		cin.ignore();
		cin >> a;

		int N;
		cin >> N;

		N *= 3;

		char str[100000];

		for(int i = 0; i < N; i++){
			cin >> str[i];
		}

		int b[10];
		for(int i = 0; i < 10; i++) b[i] = 0;
		
		for(int i = 0; i < N; i+=3){
			if(str[i] == 'Z' && str[i+1] == 'R' && str[i+2] == 'O'){  b[0]++;	continue;}
			if(str[i] == 'O' && str[i+1] == 'N' && str[i+2] == 'E'){  b[1]++;	continue;}
			if(str[i] == 'T' && str[i+1] == 'W' && str[i+2] == 'O'){  b[2]++;	continue;}
			if(str[i] == 'T' && str[i+1] == 'H' && str[i+2] == 'R'){  b[3]++;	continue;}
			if(str[i] == 'F' && str[i+1] == 'O' && str[i+2] == 'R'){  b[4]++;	continue;}
			if(str[i] == 'F' && str[i+1] == 'I' && str[i+2] == 'V'){  b[5]++;	continue;}
			if(str[i] == 'S' && str[i+1] == 'I' && str[i+2] == 'X'){  b[6]++;	continue;}
			if(str[i] == 'S' && str[i+1] == 'V' && str[i+2] == 'N'){  b[7]++;	continue;}
			if(str[i] == 'E' && str[i+1] == 'G' && str[i+2] == 'T'){  b[8]++;	continue;}
			if(str[i] == 'N' && str[i+1] == 'I' && str[i+2] == 'N'){  b[9]++;	continue;}
			
		}

		cout << "#" << test << endl;
		
		for(int j = 1; j <= b[0]; j++)	cout << "ZRO ";
		for(int j = 1; j <= b[1]; j++)	cout << "ONE ";
		for(int j = 1; j <= b[2]; j++)	cout << "TWO ";
		for(int j = 1; j <= b[3]; j++)	cout << "THR ";
		for(int j = 1; j <= b[4]; j++)	cout << "FOR ";
		for(int j = 1; j <= b[5]; j++)	cout << "FIV ";
		for(int j = 1; j <= b[6]; j++)	cout << "SIX ";
		for(int j = 1; j <= b[7]; j++)	cout << "SVN ";
		for(int j = 1; j <= b[8]; j++)	cout << "EGT ";
		for(int j = 1; j <= b[9]; j++)	cout << "NIN ";
		
		cout << endl;

	}

	return 0;

}

038202013196

BAI LADDER2

#include<iostream>
#define MIN(a, b) ((a)<=(b) ? (a) : (b))

using namespace std;
int counts[100];
int nhay;

void timduong(int matrix[100][100]){
	nhay=0;
	for(int i=0; i<100; i++){
		int x = 0;
		int y=i;
		int count = 0;
		if(matrix[x][y] == 1){
			count++;
			for(; x<100; x++){
				if(x != 0 && y+1 < 100 && matrix[x][y+1] == 1) {
					while(y+1 < 100 && matrix[x][y+1] == 1) {
						y++;
						count++;
					}
				}
				else if(x != 0 && y-1 >= 0 && matrix[x][y-1] == 1) {
					while (y-1 >= 0 && matrix[x][y-1] == 1)
					{
						y--; 
						count++;
					}
				}
				else count++;
			}
			counts[nhay]=count; 
			nhay++;
		}  else {counts[nhay]=1000; nhay++;}

	}
}

int main(){
	//("input.txt", "r", stdin);
	int test_case;
	for(test_case = 1; test_case <= 10; test_case++){
		// reset 
		for(int i=0; i<100; i++){counts[i]=1000;}
		int idx; cin >> idx;
		int matrix[100][100];
		for(int i=0; i<100; i++) {
			for(int j=0; j<100; j++){
				cin >> matrix[i][j];
			}
		}
		timduong(matrix);
		int tmp=0;
		int min = counts[0];
		for(int i=0; i<nhay; i++){
			min=MIN(min, counts[i]);
		}
		for(int i=0; i<nhay; i++){
			if(min==counts[i]) {tmp=i; break;}
		}
		cout << "#" << idx << " " << tmp << endl;
	}
	return 0;
}



BAI PATH FINDING

#include <iostream>

using namespace std;

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0};

int N;
int a[21][21];
bool visit[21][21];
bool check;

int Try(int row, int col){
	if(a[row][col] == 0 || check == true) return 0;

	if(row == N-1 && col == N-1){
		check = true;
		return 0;
	}

	for(int i = 1; i < 5; i++){
		int t = a[row][col];
		if (i == 1 && row - t >= 0 && !visit[row-t][col]) {				//xet len tren
			visit[row][col] = true;
			Try(row - t, col);
		}
		if (i == 2 && row + t < N && !visit[row+t][col]) {				//xet xuong duoi
			visit[row][col] = true;
			Try(row + t, col);
		}
		if (i == 3 && col - t >= 0 && !visit[row][col-t]) {				//xet sang trai
			visit[row][col] = true;
			Try(row, col - t);
		}
		if (i == 4 && col + t < N && !visit[row][col+t]) {				//xet sang phai
			visit[row][col] = true;
			Try(row, col + t);
		}
	}
	return 0;
}


int main(){

	//freopen("Text.txt", "r", stdin);

	int T;
	cin >> T;

	for(int test = 1; test <= T; test++){
		cin >> N;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cin >> a[i][j];
				visit[i][j] = false;
			}
		}

		visit[0][0] = true;
		check = false;
		Try(0,0);

		if(check == true) cout << "YES" << endl;
		else cout << "NO" << endl;

	}

	return 0;

}


PATH FINDING:

#include <iostream>

using namespace std;

//int dx[4] = {0, 1, 0, -1};
//int dy[4] = {1, 0, -1, 0};

int N;
int a[21][21];
bool visit[21][21];
bool check;

int Try(int row, int col){
	if(a[row][col] == 0 || check == true) return 0;

	if(row == N-1 && col == N-1){
		check = true;
		return 0;
	}

	for(int i = 1; i < 5; i++){
		int t = a[row][col];
		if (i == 1 && row - t >= 0 && !visit[row-t][col]) {				//xet len tren
			visit[row][col] = true;
			Try(row - t, col);
		}
		if (i == 2 && row + t < N && !visit[row+t][col]) {				//xet xuong duoi
			visit[row][col] = true;
			Try(row + t, col);
		}
		if (i == 3 && col - t >= 0 && !visit[row][col-t]) {				//xet sang trai
			visit[row][col] = true;
			Try(row, col - t);
		}
		if (i == 4 && col + t < N && !visit[row][col+t]) {				//xet sang phai
			visit[row][col] = true;
			Try(row, col + t);
		}
	}
	return 0;
}


int main(){

	//freopen("Text.txt", "r", stdin);

	int T;
	cin >> T;

	for(int test = 1; test <= T; test++){
		cin >> N;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cin >> a[i][j];
				visit[i][j] = false;
			}
		}

		visit[0][0] = true;
		check = false;
		Try(0,0);

		if(check == true) cout << "YES" << endl;
		else cout << "NO" << endl;

	}

	return 0;

}

Calculator 1

#include<iostream>
using namespace std;
int main()
{
	int length;
	char a[1000];
	
	
	//freopen("in3.txt" , "r", stdin);
	for(int k=1; k<=10; k++)
	{
		int sum=0;
		cin >> length;
		for(int i=0; i<length; i++)
			{
				cin >> a[i];
				if(a[i] != '+' )
				{
					sum += a[i];
					sum = sum -48;
				}
			}
	
		cout << "#" << k <<" " << sum << endl;

		
	}
	return 0;

	
}

LADDER1

#include <iostream>

using namespace std;

int main(){

	//freopen("Text.txt", "r", stdin);


	for(int test = 1; test <= 10; test++){

		int x, y;
		int a[100][100];
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++){
				cin >> a[i][j];
				if(a[i][j] == 2){
					x = i;
					y = j;
				}
			}
		}

		int i, j = y;
		for(i = x-1; i >= 0; i--){
			if(j-1 >= 0 && a[i][j-1] == 1){
				while(j-1 >= 0 && a[i][j-1] == 1){
					j--;
				}
			}
			else if(j+1 >= 0 && a[i][j+1] == 1){
				while(j+1 < 100 && a[i][j+1] == 1){
					j++;
				}
			}
			if(i == 0) break;
		}
		cout << "#" << test << " " << j-1 << endl;
	}

	return 0;

}


FINDING MODE
#include "iostream"


using namespace std;

int main(){
	int T = 10;
	int res;
	//freopen("test_input.txt", "r", stdin);
	int tmp;
	for(int t = 1; t <= T; t++) {
		
		int score[1000];
		int freq[201] = {0};
		res = 0;
		cin >> tmp;
		for(int i = 0; i < 1000; i++) {
			cin >> score[i];
			freq[score[i]]++;
		}
		int max = 0;
		int index = 0;
		for(int i = 1; i < 201; i++) {
			if(max <= freq[i]){
				max  = freq[i];
				index = i;
			}
		}

		cout << "#" << t << " " << index << endl;
	}

	return 0;

}

PASSWORD

#include <iostream>

using namespace std;

int main(){

	//freopen("input.txt", "r", stdin);
    for (int tc = 0; tc < 10; ++tc){
        int len;
        cin >> len;
        
        char arr[100] = "";
        for (int i = 0; i < len; ++i){
            cin >> arr[i];
        }

        for (int i = 0; i < len - 1; i++){
            if (arr[i] == arr[i + 1]){
                for (int j = i; j < len - 2; ++j){
                    arr[j] = arr[j + 2];
                }
                i = i - 2;
                len = len - 2;
            }
            
        }
        cout << "#" << tc + 1 << " ";
        for (int i = 0; i < len; ++i){
            cout << arr[i];
        }
        cout << endl;
	}

	return 0;

}


Palindrome 2
PALINDROME 2

#include<iostream>

using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	

	//freopen("Text.txt", "r", stdin);

	for(test_case = 1; test_case <= 10; ++test_case)
	{
		int M;
		cin >> M;
		char a[100][100];
		int ans = 0;

		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++){
				cin >> a[i][j];
			}
		}
		for(int N = 100; N > 0; N--){
			for(int i = 0; i < 100; i++){
				for(int j = 0; j < 100; j++){
					if(j + N > 100) break;
					char h[100], c[100];
					for(int k = 0; k < N; k++){
						h[k] = a[i][k+j];
						c[k] = a[k+j][i];
					}
					for(int k = 0; k < N/2; k++){
						if(h[k] != h[N-k-1]) break;
						if(k == N/2 -1) ans++;
					}
					for(int k = 0; k < N/2; k++){
						if(c[k] != c[N-k-1]) break;
						if(k == N/2 -1) ans++;
					}
				}
			}
			if(ans > 0) {
				cout << "#" << M << " " << N << endl;
				break;
			}
		}
		

		//cout << "#" << M << " " << ans << endl;
	}
	return 0;//Your program should return 0 on normal termination.
}


LADDER 1

// In Practice, You should use the statndard input/output
// in order to receive a score properly.
// Do not use file input and output. Please be very careful. 

#include <stdio.h>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
	int tc, T;
	
	// The freopen function below opens input.txt file in read only mode, and afterward,
	// the program will read from input.txt file instead of standard(keyboard) input.
	// To test your program, you may save input data in input.txt file,
	// and use freopen function to read from the file when using cin function.
	// You may remove the comment symbols(//) in the below statement and use it.
	// Use #include<cstdio> or #include<stdio.h> to use the function in your program.
	// But before submission, you must remove the freopen function or rewrite comment symbols(//).

	//freopen("input.txt", "r", stdin);

//	cin >> T;
	//int n=100;
	for(tc = 1; tc <= 10; tc++)
	{
        cin >> T;
		/*int t;
		cin>>t;*/
		/**********************************
		*  Implement your algorithm here. *
		***********************************/
		int data[100][100];
		int start =0;
		for(int i= 0;i< 100; i++){
			for(int j= 0;j <100; j++){
				cin>>data[i][j];
			}
		}
			//diem dich
		for(int i=0;i<100;i++){
			if(data[99][i]==2){
				start=i;
				break;
			}
		}
			
		
		for(int i =99;i >=0; i--){
			//dich ve ben trai
			if(start -1 >=0 &&data[i][start-1] ==1){
				while (start-1>=0&&data[i][start-1] ==1)
				{
					start--;
				}
			//dich ve ben phai
			
			}
			else if(start +1<100&&data[i][start+1]==1){
				while (start +1<100&&data[i][start+1]==1)
				{
					start++;
				}
			}
		//di len tren

		
		}	
		// Print the answer to standard output(screen).	
		cout<<"#"<<tc<<" "<<start<<endl;
	}
	return 0;//Your program should return 0 on normal termination.
}

PASSWORD

#include <iostream>

using namespace std;

int main(){

	//freopen("input.txt", "r", stdin);
    for (int tc = 0; tc < 10; ++tc){
        int len;
        cin >> len;
        
        char arr[100] = "";
        for (int i = 0; i < len; ++i){
            cin >> arr[i];
        }

        for (int i = 0; i < len - 1; i++){
            if (arr[i] == arr[i + 1]){
                for (int j = i; j < len - 2; ++j){
                    arr[j] = arr[j + 2];
                }
                i = i - 2;
                len = len - 2;
            }
            
        }
        cout << "#" << tc + 1 << " ";
        for (int i = 0; i < len; ++i){
            cout << arr[i];
        }
        cout << endl;
	}

	return 0;

}

PASSWORD

#include <iostream>
using namespace std;

void createPassword(char input[],int n) {
    char password[100];
    int top = -1; 
    for (int i = 0; i < n; ++i) {
        if (top >= 0 && password[top] == input[i]) {
    
            top--;
        } else {
            password[++top] = input[i];
        }
    }

    for (int i = 0; i <=top; ++i) {
        cout<< password[i];
    }

  cout<<endl;
}

int main() {
	//freopen("intput.txt","r",stdin);
    for (int tc = 1; tc <= 10; ++tc) {
        int N;
        cin >> N;

        char input[N];
        for(int i=0;i<N;i++)
        cin >> input[i];
        cout << "#" << tc << " ";
        createPassword(input,N);
    }

    return 0;
}


DI CHUYEN BO

#include <stdio.h>
#include <iostream>

#define MAX(a, b) ((a)>(b)?a:b)

using namespace std;

int main()
{
	int T; cin >> T;
	for(int tc = 0; tc < 20; tc++)
	{
		//Nhap lieu
		int car, numCow;
		cin >> car >> numCow;
		int weight[100000];
		int idx=0;
		for(int i=0; i<numCow; ++i){
			int cow; cin >> cow;
			weight[idx]=cow;
			idx++;
			for(int j=idx-2; j>=0; j--) {
				int tmp = cow+weight[j];
				weight[idx] = tmp;
				idx++;
			}
		}
		int maxLoad=weight[0];
		for(int i=1; i<idx; i++){
			if(weight[i]<=car) maxLoad=MAX(maxLoad, weight[i]);
			else continue;
		}
		cout << "#" << tc+1 << " " << maxLoad << endl;

	}
	return 0;
}

FINDING MODE

#include "iostream"


using namespace std;

int main(){
	int T = 10;
	int res;
	//freopen("test_input.txt", "r", stdin);
	int tmp;
	for(int t = 1; t <= T; t++) {
		
		int score[1000];
		int freq[201] = {0};
		res = 0;
		cin >> tmp;
		for(int i = 0; i < 1000; i++) {
			cin >> score[i];
			freq[score[i]]++;
		}
		int max = 0;
		int index = 0;
		for(int i = 1; i < 201; i++) {
			if(max <= freq[i]){
				max  = freq[i];
				index = i;
			}
		}

		cout << "#" << t << " " << index << endl;
	}

	return 0;

}


VMV THI THU CHIEU 10.8 (Hieu)

#include <iostream>
using namespace std;

int tx[4] = {-1, 0, 1, 0};
int ty[4] = {0, 1, 0, -1};

int main (){

	freopen("input.txt", "r", stdin);
	int T;
	cin >> T;
	for(int test_case = 1; test_case <= T; test_case++) {
		int size;
		cin >> size;
		char arr[100][100];
		for(int i = 0; i < size; i++) {
			for(int j = 0; j < size; j++) {
				cin >> arr[i][j];
			}
		}
		
		for(int i = 0; i < size; i++) {
			for(int j = 0; j < size; j++) {
				if(arr[i][j] == 'A' || arr[i][j] == 'B' || arr[i][j] == 'C') {
					for(int k = 0; k < 4; k++) {
						int u = i+tx[k];
						int v = j+ty[k];
						if(u >= 0 && v>=0 && u<=size && v<=size && (arr[u][v] == 'H' || arr[u][v] == 'X')) {
							arr[u][v] = 'O';
						}
					}
				}
				if(arr[i][j] == 'B' || arr[i][j] == 'C') {
					for(int k = 0; k < 4; k++) {
						int u = i+tx[k]*2;
						int v = j+ty[k]*2;
						if(u >= 0 && v>=0 && u<=size && v<=size && (arr[u][v] == 'H' || arr[u][v] == 'X')) {
							arr[u][v] = 'O';
						}
					}
				}
				if(arr[i][j] == 'C') {
					for(int k = 0; k < 4; k++) {
						int u = i+tx[k]*3;
						int v = j+ty[k]*3;
						if(u >= 0 && v>=0 && u<=size && v<=size && (arr[u][v] == 'H' || arr[u][v] == 'X')) {
							arr[u][v] = 'O';
						}
					}
				}
			}
		}
		int count = 0;
		for(int i = 0; i < size; i++) {
			for(int j = 0; j < size; j++) {
				if(arr[i][j] == 'H') {
					count++;
				}
			}
		}
		cout << "#" << test_case << " " << count << endl;
	}
	return 0;
}

THI THU CHIEU 10.8 DUNG
#include <iostream>

using namespace std;

int main(){

	freopen("input.txt", "r", stdin);
    int test;
    cin >> test;
    for (int tc = 0; tc < 10; ++tc)
    {
        int len;
        cin >> len;
        int a[12] = { -1 , 1 , 0 , 0 };
        int b[12] = { 0 , 0 , -1 , 1};
        int e[12] = { -1 , 1 , 0 , 0 , -2 , 2 , 0 , 0};
        int f[12] = { 0 , 0 , -1 , 1 , 0 , 0 , -2 , 2};
        int x[12] = { -1 , 1 , 0 , 0 , -2 , 2 , 0 , 0 , -3 , 3 , 0 , 0 };
        int y[12] = { 0 , 0 , -1 , 1 , 0 , 0 , -2 , 2 , 0, 0 , -3 , 3 };
        char arr[103][103];
        for (int i = 0; i < len; i++)
        {
            for( int j = 0; j < len; j++)
            {
                cin >> arr[i][j];
            }
        }

       for (int i = 0; i < len; i++)
        {
            for( int j = 0; j < len; j++)
            {
                if( arr[i][j] == 'A' )
                {
                    for( int m = 0; m < 4; m++)
                    {
                        if( arr[i + a[m]][ j+b[m]] == 'H')
                        {
                            arr[i + a[m]][ j+b[m]] = 'X';
                        }
                    }
                }

                if( arr[i][j] == 'B' )
                {
                    for( int m = 0; m < 8; m++)
                    {
                        if( arr[i + e[m]][ j+f[m]] == 'H')
                        {
                            arr[i + e[m]][ j+f[m]] = 'X';
                        }
                    }
                }

                if( arr[i][j] == 'C' )
                {
                    for( int m = 0; m < 12; m++)
                    {
                        if( arr[i + x[m]][ j+y[m]] == 'H' )
                        {
                            arr[i + x[m]][ j+y[m]] = 'X';
                        }
                    }
                }
            }
       }

       int count = 0;
       for (int i = 0; i < len; i++)
        {
            for( int j = 0; j < len; j++)
            {
                if(arr[i][j] == 'H')
                    count ++;
            }
       }
       cout << "#" << tc+1 << " " << count << endl;
    }
	return 0;

}

STOCK EXCHANGE 

#include <iostream>

using namespace std;

int main(){

	//freopen("Text.txt", "r", stdin);

	int T;
	cin >> T;

	for(int test = 1; test <= T; test++){
		int N;
		cin >> N;

		int a[1000];
		for(int i = 0; i < N; i++) cin >> a[i];

		int ans = 0;

		int m = 0;
		while(m < N){
			int maxx = 0; 
			int vtmax = -1;
			if(m == N-1) break;
			for(int i = m; i < N; i++){
				if(a[i] > maxx){
					maxx = a[i];
					vtmax = i;
				}
			}
			if(vtmax != -1){
				for(int i = m; i < vtmax; i++){
					ans += a[vtmax] - a[i];
				}
				m = vtmax+1;
			}

		}

		cout << "#" << test << " " << ans << endl;
	}

	return 0;
}

STOCK EXCHANGE

#include <iostream>
using namespace std;
	int idx;
	int profitt=0;
int profit(int arr[],int k,int n){
	if(k>=n-1){
		return profitt;
	}
	int maxx=0;
	int sum=0;
	for(int i=k;i<n;i++){
		if(maxx<arr[i]){
			maxx=arr[i];
			idx=i;
		}
	}
	if(maxx==arr[k]){
				sum=0;
			}
	else{
		for(int i=k;i<idx;i++){
				profitt+=maxx-arr[i];
				}
			}
		profit(arr,idx+1,n);
}

int main() {
	//freopen("intput.txt","r",stdin);
    int T;
    cin >> T;
    for (int t = 1; t <= T; ++t) {
        int n;
		cin>>n;
		profitt=0;
		int a[30];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		int ans=profit(a,0,n);
		cout<<"#"<<t<<" "<<ans<<endl; 
    }

    return 0;
}


THI THU CHIEU 10.8 
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int ans;
int a[101][101];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void check(int row, int col){
	int xx[4] = {1,3,5,7};
	int yy[4] = {2,4,6,8};
	int cnt = 0;
	int tempX = row, tempY = col;
	for(int z = 0; z < 4; z++) {
		xx[z] = tempX, yy[z] = tempY;
		int x = xx[z], y = yy[z];
		if(a[x][y] == 1) {
			while(x+dx[z] >= 0 && x+dx[z] < 100 && y+dy[z] >=0 && y+dy[z] < 100 && a[x+dx[z]][y+dy[z]] == 1){
				cnt++, a[x][y]--;
				x+=dx[z], y+=dy[z];
			}
			tempX = x, tempY = y;
		} else return;
	}
	if(a[tempX][tempY] == 1) a[tempX][tempY]--, cnt++;
	if(xx[0] == xx[1] && yy[1] == yy[2] && xx[2] == xx[3] && yy[3] == yy[0]){
		if(yy[1] - yy[0] >=2 && xx[3] - xx[0] >= 2){
			if(cnt == 2*(yy[1] - yy[0] + xx[3] - xx[0] + 2) - 4) ans++;
		}
	}
}

int main(){
	freopen("input.txt", "r", stdin);

	for(int test_case = 1; test_case <= 10; test_case++) {
		int tc;
		cin >> tc;
		ans = 0;
		for(int i = 0; i < 100; i++) {
			for(int j = 0; j < 100; j++) cin >> a[i][j];
		}

		for(int i = 0; i < 100; i++) {
			for(int j = 0; j < 100; j++) {
				if(a[i][j] == 1) check(i, j);
			}
		}
		cout << "#" << tc << " " << ans << endl;	
	}
	return 0;
}

MAZE 2

#include<iostream>
using namespace std;
char a[101][101];
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
int s,t;
int dfs(int x,int y){
	if(a[x][y]=='3'){
		return true;
	}
	a[x][y]='1';
	for(int k=0;k<4;k++){
		int x1=x+dx[k];
		int y1=y+dy[k];
		if(x1>=0 && x1<100 && y1>=0 && y1<100 && a[x1][y1]!='1'){
			if(dfs(x1,y1)){
				return true;
			}
		}
	}
	return false;
}
int main(){
	//freopen("input1.txt","r",stdin);
	for(int tc = 1; tc <= 10; tc++){
		int n;
		cin>>n;
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				cin>>a[i][j];
				if(a[i][j]=='2'){
					s=i;
					t=j;
				}
			}
		}
		
		cout<<"#"<<tc<<" "<<dfs(s,t)<<endl;
	}
	return 0;
}
Assimilation of String

#include <iostream>

using namespace std;
	
int N, row, col;
int a[200][200];
int ans;

int main(){

	//freopen("Text.txt", "r", stdin);

	int T;
	cin >> T;

	for(int test = 1; test <= T; test++){
		cin >> N;
		char A[1000], B[1000], C[1000];
		for(int i = 0; i < N; i++) cin >> A[i];
		for(int i = 0; i < N; i++) cin >> B[i];
		for(int i = 0; i < N; i++) cin >> C[i];

		ans = 0;

		for(int i = 0; i < N; i++){
			if(A[i] == B[i] && A[i] == C[i]) continue;
			if((A[i] == B[i] && A[i] != C[i]) || (A[i] != B[i] && A[i] == C[i]) ||(A[i] != B[i] && B[i] == C[i])){
				ans++;
				continue;
			}
			if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]){
				ans+=2;
				continue;
			}
		}

		cout << "#" << test << " " << ans << endl;

	}

	return 0;

}

THI THU PHAN XA GUONG (Hieu)


#include <iostream>

using namespace std;

int main(){
    // freopen("input.txt", "r", stdin);
    int T;
    cin >> T;
    for (int tc = 1; tc <= T; ++tc){
        int n;
        cin >> n;
        int arr[100][100];
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                cin >> arr[i][j];
            }
        }

        int cnt = 0;
        int i = 0;
        int j = 0;
        int vector_x = 1; // left = 1; right = -1
        int vector_y = 0; // down = -1; up = 1
        while (i >= 0 && i < n && j >= 0 && j < n) {
            if (arr[i][j] == 0) { 
                i += vector_y;
                j += vector_x;
            }
            else if (arr[i][j] == 2) {
                cnt++;
                if (vector_x != 0){
                    i += vector_x;
                    vector_y = vector_x;
                    vector_x = 0;
                }
                else if (vector_y != 0) {
                    j += vector_y; 
                    vector_x = vector_y; 
                    vector_y = 0; 
                }
            }
            else if (arr[i][j] == 1) {
                cnt++;
                if (vector_x != 0) {
                    i -= vector_x;
                    vector_y = 0 - vector_x;
                    vector_x = 0;
                }
                else if (vector_y != 0 ) {
                    j -= vector_y;
                    vector_x = 0- vector_y;
                    vector_y = 0;
                }
            }
        }
        cout << "#" << tc << " " << cnt << endl;
    }

    return 0;
}

BAI LAKE tim duong ngan nhat ve bo

#include <iostream>

using namespace std;

int T;
int N;
int arr[100][100];
int Answer;

int main() {
	int test_case;
	int i, j;

	// Delete this line when submit on server
	// freopen("Text.txt", "r", stdin);

	cin >> T;

	for (test_case = 1; test_case <= T; test_case++) {
		cin >> N;
		// Get the array
		for (i = 0; i < N; i++)
			for (j = 0; j < N; j++)
				cin >> arr[i][j];
		// Your algorithm here
		Answer = 0;

		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(arr[i][j] != 0) {
					int check[4] = {0, 0, 0, 0};
					int ii = i, jj = j;
					while(arr[i][j] != 0) {		// up
						check[0]++;
						i--;
					}
					i = ii; 
					j = jj; 

					while(arr[i][j] != 0) {		// down
						check[1]++;
						i++;
					}
					i = ii; 
					j = jj; 

					while(arr[i][j] != 0) {		// left
						check[2]++; 
						j--; 
					}
					i = ii;
					j = jj;

					while(arr[i][j] != 0) {		// right
						check[3]++;
						j++;
					}

					i = ii;
					j = jj;

					int min = check[0];
					for(int m = 0; m < 4; m++) {
						if(check[m] < min) min = check[m];
					}

					Answer += min;
				}
			}
		}

		cout << "#" << test_case << " " << Answer << endl;
	}

	return 0;
}