0% found this document useful (0 votes)
13 views10 pages

Unit 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

Unit 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

#include<bits/stdc++.

h>

using namespace std;

int main(){

int n;

cin>>n;

int a[n][n];

int sum = 0;

int sym = 0;

for(int i = 0; i<n;i++){

for(int j = 0;j<n;j++){

cin>>a[i][j];

for(int i = 0; i<n;i++){

for(int j = 0;j<n;j++){

if(i==j) sum = sum + a[i][j];

for(int i = 0; i<n;i++){

for(int j = 0;j<n;j++){

if(i+j==n-1) sym = sym + a[i][j];

cout<<"Tong cac phan tu tren duong cheo chinh la : "<<sum<<endl;

cout<<"Tong cac phan tu tren duong cheo phu la : "<<sym;

return 0;

}
#include<bits/stdc++.h>

using namespace std;

int main(){

int n,m;

cin>>n>>m;

int a[n][m];

vector<int> v;

int it = 0;

vector<int> mi;

vector<int> x;

for(int i = 0; i<n;i++){

for(int j = 0;j<m;j++){

cin>>a[i][j];

int min = a[0][0];

for(int i = 0; i<n;i++){

for(int j = 0;j<m;j++){

if(min>=a[i][j]){

min = a[i][j];

mi.push_back(min);
for(int j = 0;j<m;j++){

if(a[i][j]==min){

v.push_back(j);

min = a[i+1][0];

int max = a[0][v[1]];

for(int i = 0;i<v.size();i++){

for(int j = 0;j<n;j++){

if(max<a[j][v[i]]) max = a[j][v[i]];

x.push_back(max);

max = a[0][v[i+1]];

for(int i = 0;i<x.size();i++){

if(x[i]==mi[i]) cout<<x[i]<<" ";

#include <bits/stdc++.h>

using namespace std;

int main(){

int n;
cin>>n;

int a[n][n];

int h1 = 0, h2 = n - 1, c1 = 0, c2 = n - 1;

int dem = n*n;

while(h1 <= h2 && c1 <= c2){

for(int i = c1; i<=c2; i++){

a[h1][i] = dem; --dem;

++h1;

for(int i = h1; i <= h2; i++){

a[i][c2] = dem; --dem;

--c2;

for(int i = c2; i >= c1; i--){

a[h2][i] = dem; --dem;

--h2;

for(int i = h2; i >= h1; i--){

a[i][c1] = dem; --dem;

++c1;

for(int i = 0; i < n; i++){

for(int j = 0; j < n; j++){

cout<<a[i][j]<<" ";

cout<<endl;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

int n,m;

cin>>n>>m;

int k;

cin>>k;

int a[n+1][m+1];

for(int i = 1;i<=n;i++){

for(int j = 1;j<=m;j++){

cin>>a[i][j];

vector<int> s;

vector<int> d;

int max= 0;

int pre[n+1][m+1] = {0};

for(int i = 1;i<=n;i++){

for(int j = 1;j<=m;j++){

pre[i][j] = pre[i][j-1] + pre[i-1][j] - pre[i-1][j-1] + a[i][j];

}
int h1,h2,c1,c2;

for(int h1 = 1;h1<=n;h1++){

for(int h2 = h1;h2<=n;h2++){

for(int c1 = 1;c1<=m;c1++){

for(int c2 = c1;c2<=m;c2++){

s.push_back(pre[h2][c2]-pre[h1-1][c2]-pre[h2][c1-1]+pre[h1-1][c1-1]);

for(int i = 0;i<s.size();i++){

if(s[i]<=k) d.push_back(s[i]);

for(int i = 0;i<d.size();i++){

if(max<=d[i]) max = d[i];

cout<<max;

#include <bits/stdc++.h>

using namespace std;

void lai(int m){

cout<<"Doan so tu 1 den 20"<<endl;

srand(time(0));

int n = 1 + rand()%20;
while(m!=n){

cin>>m;

if(m<n) cout<<"So do lon hon nua\n";

if(m>n) cout<<"So do nho hon nua\n";

cout<<"Chuc mung , ban da doan dung";

cout<<endl<<"Ban choi nua khong ? Bam 'Co' hoac 'Khong'!"<<endl;

int main(){

int m;

lai(m);

string b;

int cnt = 1;

while(cnt!=-1){

cin>>b;

if(b.size()==2){

if(b[0]=='C'&&b[1]=='o'){

lai(m);

cnt++;

else if(b[0]=='c'&&b[1]=='o'){

lai(m);

cnt++;

else if(b[0]=='c'&&b[1]=='O'){

lai(m);

cnt++;
}

else if(b[0]=='C'&&b[1]=='O'){

lai(m);

cnt++;

else cnt = -1;

if(b.size()!=2) cnt = -1;

if(cnt==-1) break;

#include<bits/stdc++.h>
using namespace std;

void lai(int ans){

int n,m;

int x,y,z;

srand(time(0));

cout<<"May kiem tra tinh toan cua ban tu n den m"<<endl;

cout<<"n : " ; cin>>n;

cout<<"m : "; cin>>m;

int rec = 0;

while(ans == rec){

srand(time(0));

x = n + rand()%(m-n+1);

y = n + rand()%(m-n+1);

z = m+1+rand()%2;

if(z==m+1){

cout<<x<<" + "<<y<<endl;

rec = x+y;

if(z==m+2){

cout<<x<<" - "<<y<<endl;

rec = x-y;

cin>>ans;

cout<<"NGU ! Dap an phai la : "<<rec<<endl;

cout<<"Ban choi nua khong ? Bam 'Co' hoac 'Khong' de xac nhan"<<endl;

}
int main(){

int ans;

lai(ans);

string b;

int cnt = -1;

while(cnt==-1){

cin>>b;

if(b=="Co"||b=="co"||b=="cO"||b=="CO") lai(ans);

else break;

You might also like