Teza Olimpiada Bruno Plaku
Teza Olimpiada Bruno Plaku
Teza Olimpiada Bruno Plaku
Ushtrimi 4:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i,j,n;
int tabela[20][20];
cout<<"Jep n="<<endl;
cin>>n;
cout<<"Jep elem e tabe"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>tabela[i][j];
}
}
// afishimi
cout<<"Afishimi"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<setw(5)<<tabela[i][j];
}
cout<<endl<<endl;
}
int sasia=0;
// zgjidhja
for(j=0;j<n;j++)
{
sasia=sasia+1;
if(sasia %2 !=0)
{
for(i=0;i<n;i++)
Ushtrimi 3:
Ushtrimi 2:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i,j,k=0,temp;
int Matrica[3][3]={{2,4,8}, {4,7,-6},{10,4,0}};
//Afishimi i matrices
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<setw(6)<<Matrica[i][j];
}
cout<<endl<<endl;
}
cout<<"___________________________________"<<endl;
// Paraqitje e elementeve te diagonale kryesore
for(i=0;i<3;i++)
cout<<setw(3)<<Matrica[i][i]<<endl;
cout<<"______________________________"<<endl;
// renditja e diagonales kryesore nga me i A-Z
for(i=0;i<3;i++)
{
for(k=i+1;k<3;k++)
{
if(Matrica[i][i]>Matrica[k][k])
{
temp=Matrica[i][i];
Matrica[i][i]=Matrica[k][k];
Matrica[k][k]=temp;
}
}
}
// Afishimi i renditur sipas diagonales kryesore A-Z
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<setw(6)<<Matrica[i][j];
}
cout<<endl<<endl;
}
return 0;
}
Ushtrimi 1:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int sa_fjaleve=0;
int s_hapesires=0;
char fjala;
cout << "Shkruaj fjalin (!fjalia do pike ne fund te fjalise)" << endl;
cin.get(fjala);
while(fjala!='.')
{
if(fjala==' ')
sa_fjaleve=sa_fjaleve+1;
s_hapesires=s_hapesires+1;
cin.get(fjala);
}
cout<<"Sasia e fjaleve :"<<sa_fjaleve<<endl;
cout<<"Sasia e hapesires :"<<s_hapesires<<endl;
return 0;
}
Ushtrimi 5:
#include <vector>
#include <iostream>
#include <iomanip>
#include <thread>
#include <future>
using namespace std;
static void print(const std::vector<int>&pos)
{
for (int i=0;i<pos.size();i++)
{
std::cout<<std::setw(3)<<char('a'+i);
}
std::cout<<'\n';
for (int row=0;row<pos.size();row++)
{
int col=pos[row];
std::cout<<row+1<<std::setw(3*col+3)<<"#";
std::cout<<'\n';
}
std::cout<<"\n\n";
}
static bool good(const std::vector<int>&pos,int end_idx)
{
for(int row_a=0;row_a<end_idx;row_a++){
for(int row_b=row_a+1;row_b<end_idx;row_b++){
int col_a=pos[row_a];
int col_b=pos[row_b];
if(threatens(row_a,col_a,row_b,col_b))
{
return false;
}
}
}
return true;
}
static void n_queens(std::vector<int>&pos,int index)
{
if(index>=pos.size()){
if(good(pos,index)){
std::lock_guard<std::mutex>lock(print_count_mutex);
print(pos);
n_sols++;
}
return;
}
if(not good(pos,index)){