Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 12.05.2009, 11:52   #1
AFA
Пользователь
 
Регистрация: 19.04.2009
Сообщений: 69
По умолчанию Задача на с++

Задача о замочной скважине.
В 2-х файлах находятся рисунки замочной скажины и ключа (из 0 и 1).Определить подойдёт ли данный ключ к замочной скважине, используя операции сдвига и поворота на 90 градусов.
Программу я таки написал..но не знаю как сделать повороты на 90 градусов. Помогите!
Код:
#include <windows.h> 
 #include <iostream.h>      
#include <fstream>  using namespace std;   
HANDLE hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE ); 
void ust_coord(int x, int y)
{	COORD c;
    c.X=x;    c.Y=y;
	SetConsoleCursorPosition(hConsoleOut,c);
}
void clear()
{	ust_coord(0,0);             	for (int i=0; i<40; i++)
		for (int j=0; j<80; j++)
			printf("		ust_coord(0,0);
}
void rus(char *PtrStr)
{   	char Str[255]; 
	CharToOem(PtrStr,Str);  
	cout<<Str;
}
int menu(int u)
{    clear();      
 int k; 
cout<<"\n\t =========================================\n";
 if (u==1)  rus("\t||\t Выберите  вид  ЗАМКА:\t\t ||\n\t||\t\t\t\t\t ||\n"); 
 else       rus("\t||\t Выберите  вид  КЛЮЧА:\t\t ||\n\t||\t\t\t\t\t ||\n");
 cout<<"\t|-----------------------------------------|\n";
 rus("\t||  Замок...........................1    ||\n");
cout<<"\n\t =========================================\n";
 cin>>k;
 return k;
}
int error(void)
{    clear();
  int q;
  rus("\n\n\t\tОшибка ввода!!!\n"); 
  rus("\n\tЧтобы ввести данные занова нажмите 1\n");   rus("\n\tДля выхода из программы нажмите 2\n");
  cin>>q;
  if(q==1)   return 1; 
  else  return 0;
}
void main()
{   	int dlina=0,shir=0;
 int dlina1=0,shir1=0;
 int Mas[50][50],Mas2[50][50];
 int i,j,k,e=1;
ifstream Z_File;
 while(e!=0 && e!=2)   
	{
	 k=menu(1);       
     if(k==1)      { Z_File.open("Z_Kvadrat.txt", ios::in); e=2;} 
     else if(k==2)   { Z_File.open("Z_Kluch.txt", ios::in);   e=2;}  
	 else e=error	} 
 if(e==0) return;     
 e=1;  
ifstream K_File;
 while(e!=0 && e!=2)   
	{ 	 k=menu(2);       
      if(k==1)      { Z_File.open("Z_Kvadrat.txt", ios::in); e=2;} 
     else if(k==2)   { Z_File.open("Z_Kluch.txt", ios::in);   e=2;}  
	} 
 if(e==0) return;     
 clear();
 rus("\t     И с х о д н ы е    м а т р и ц ы\n"); 
 rus("\n\t\t\t К Л Ю Ч :\n");
  K_File>>dlina>>shir;
 for( i=0;i<dlina;i++)
	{cout<<"\n\t\t      ";
     for(j=0;j<shir;j++)
		 {K_File>>Mas[i][j];   
          cout<<Mas[i][j]; 
		} 
 }
rus("\n\n\t\t\tЗ А М О К :");
Z_File>>dlina1>>shir1;
cout<<"\n";
 for( i=0;i<dlina1;i++)
 {
  cout<<"\n\t\t    ";
  for( j=0;j<shir1;j++)
	 {  	  Z_File>>Mas2[i][j];
      cout<<Mas2[i][j];
	 }
 }
int x1=10000,x2=10000;
int y1=10000,y2=20000;
int LenX1=0,LenX2=0;
int LenY1=0,LenY2=0;
int rez=0;
for( i=0;i<dlina;i++)
	{	 for( j=0;j<shir;j++)
		{
		 if(Mas[i][j]==0 && j<x1)
		   x1=j;
	     if(Mas[i][j]==0 && i<y1)
		   y1=i;
		}
	}
  for( i=0;i<dlina1;i++)
	{
	  for( j=0;j<shir1;j++)
		{  if(Mas2[i][j]==1 && j<x2)
		   x2=j;
	     if(Mas2[i][j]==1 && i<y2)
		    y2=i;
		}
  }               
cout<<"\n\n\n\t -----------------------------------\n";
 rus("\t| Координаты начала | Ключа | Замка |\n");
 cout<<"\t|-----------------------------------|\n";
 cout<<"\t|    \t   X\t    |\t"<<x1<<"   |\t"<<y1<<"   |\n";
 cout<<"\t|-----------------------------------|\n";
 cout<<"\t|    \t   Y\t    |  ";   cout.width(2);      cout<<x2<<"   |\t"<<y2<<"   |\n";
 cout<<"\t|-----------------------------------|\n";
  for( i=0;i<(dlina);i++)
	for( j=0;j<(shir-1);j++)
	   if(Mas[i][j]==0 && Mas[i][j+1]==1 && j>LenX1)
		  LenX1=j;
  for( i=0;i<(dlina-1);i++)
    for( j=0;j<(shir);j++)
       if(Mas[i][j]==0 && Mas[i+1][j]==1 && i>LenY1)
		  LenY1=i;
     for( i=0;i<(dlina1);i++)
    for( j=0;j<(shir1-1);j++)
       if(Mas2[i][j]==1 && Mas2[i][j+1]==0 && j>LenX2)
	   	  LenX2=j;
  for( i=0;i<(dlina1-1);i++)
    for( j=0;j<(shir1);j++)
       if(Mas2[i][j]==1 && Mas2[i+1][j]==0 && i>LenY2)
      	  LenY2=i;
     LenX1-=--x1;
 LenX2-=--x2;
 LenY1-=--y1;
 LenY2-=--y2;
  rus("\t|       Ширина\t    |  "); cout.width(2);  
 cout<<LenX1<<"   |  "; cout.width(2); cout<<LenX2<<"   |\n";
 cout<<"\t|-----------------------------------|\n";
 rus("\t|       Высота\t    |  ");  cout.width(2); 
 cout<<LenY1<<"   |  ";   cout.width(2); cout<<LenY2<<"   |\n";
 cout<<"\t -----------------------------------\n";
cout<<"\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
 cout<<"\t\t!! \t\t\t    !!";                       
 if(LenX1==LenX2 && LenY1==LenY2)
	{	 cout<<'\n';
	 for( i=1;i<=LenY1;i++)
		for( j=1;j<=LenX1;j++)
			if(Mas2[y2+i][x2+j]==Mas[y1+i][x1+j])
			    rez++;                   
	 if(rez==0)
		rus("\t\t!!  Ключ к замку ПОДХОДИТ   !!\n");
	 else
		rus("\t\t!! Ключ к замку НЕ ПОДХОДИТ !!\n");
	}
 else
     rus("\n\t\t!! Ключ к замку НЕ ПОДХОДИТ !!\n");
 cout<<"\t\t!! \t\t\t    !!\n";
 cout<<"\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n";
}
K_Kluch.txt

K_Kvadrat.txt

Z_Kluch.txt

Z_Kvadrat.txt
AFA вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц