Cod sursa(job #231730)
Utilizator | Data | 14 decembrie 2008 12:52:48 | |
---|---|---|---|
Problema | Tablete | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Algoritmiada 2009, Runda 1, Clasele 5-8 | Marime | 1.21 kb |
#include<fstream>
using namespace std;
int main(){
ifstream in("tablete.in");
ofstream out("tablete.out");
long long n,k,i,j;
in>>n;
in>>k;
if(k%2==0){
for(i=1;i<=n;i++){
for(j=1;j<n;j++) out<<n*(i-1)+j<<" ";
out<<n*(i-1)+j<<endl;
}
}
else { for(i=1;i<=n;i++){
if(i==1){
for(j=1;j<k;j++) out<<n*(i-1)+j<<" ";
for(j=k;j<n;j++) out<<n*(i-1)+j+1<<" ";
out<<n*(i-1)+j+1<<endl;
}
else{
out<<n*(i-2)+k<<" ";
for(j=2;j<n;j++) out<<n*(i-1)+j<<" ";
out<<n*(i-1)+j<<endl;
}
}
}
return 0;
}