Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int a[5][5], b[50];
- void sett()
- {
- for(int i = 1;i<6;i++)
- {
- b[i-1] = i;
- }
- }
- bool cq(int n)
- {
- for(int i = 0;i<50;i++)
- {
- if(b[i]==n)
- return true;
- }
- return false;
- }
- int Shift(int row, int value)
- {
- int temp;
- for(int i = row;i<row+1;i++)
- {
- for(int j = 0;j<5;j++)
- {
- temp = a[i][j];
- a[i][j] = value;
- value = temp;
- }
- }
- }
- int Min_Cq()
- {
- int Min = 9999999, ans = 0, R;
- for(int i = 0;i<5;i++)
- {
- ans = 0;
- for(int j = 0;j<5;j++)
- {
- int num = a[i][j];
- if(num==1)
- {
- if(j==0){ ans = ans + 16;}
- else if(j==1) { ans = ans + 8;}
- else if(j==2) { ans = ans + 4;}
- else if(j==3) { ans = ans + 2;}
- else if(j==4) { ans = ans + 1;}
- }
- }
- if(Min>ans)
- {
- Min = ans;
- R = i;
- }
- }
- return R;
- }
- int main()
- {
- sett();
- for(int i = 0;i<5;i++)
- {
- for(int j = 0;j<5;j++)
- {
- a[i][j] = 0;
- }
- }
- cout<<"What Operation u want to prefer ? for read bit type 1, for inserting enter 2 : "<<endl;
- int N;
- while(cin>>N)
- {
- cout<<endl;
- if(N==1)
- {
- for(int i = 0; i<5; i++)
- {
- cin>>N;
- Shift(i,N);
- }
- cout<<endl;
- for(int i = 0; i<5; i++)
- {
- for(int j = 0; j<5; j++)
- {
- cout<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- else if(N==2)
- {
- int res = Min_Cq();
- cout<<"Enter shifting value :"<<endl<<endl;
- cin>>N;
- int T = 1;
- for(int i =0;i<50;i++)
- {
- if(b[i]==N)
- {
- T = 0;
- }
- }
- if(T){
- for(int i = 0;i<5;i++)
- {
- if(i==0){ a[res][i] = 1;}
- else{
- a[res][i] = 0;
- }
- }
- }
- else{
- Shift(N,1);
- }
- for(int i = 0; i<5; i++)
- {
- for(int j = 0; j<5; j++)
- {
- cout<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- cout<<"What Operation u want to prefer ? for read bit type 1, for inserting enter 2 : "<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement