- 1
QVector<double*>*** ElemBoundCond = tbc->getElementsBC();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 51
+28
QVector<double*>*** ElemBoundCond = tbc->getElementsBC();
+106
for i:= 1 to 24 do read (a[i]);
if (abs(sqrt ((a[1]-a[4])*(a[1]-a[4])+(a[2]-a[5])*(a[2]-a[5])+(a[3]-a[6])*(a[3]-a[6]))) = abs(sqrt ((a[4]-a[7])*(a[4]-a[7])+(a[5]-a[8])*(a[5]-a[8])+(a[6]-a[9])*(a[6]-a[9]))) and
(abs(sqrt ((a[4]-a[7])*(a[4]-a[7])+(a[5]-a[8])*(a[5]-a[8])+(a[6]-a[9])*(a[6]-a[9]))) =abs(sqrt ((a[7]-a[10])*(a[7]-a[10])+(a[8]-a[11])*(a[8]-a[11])+(a[9]-a[12])*(a[9]-a[12]))) and
(abs(sqrt ((a[7]-a[10])*(a[7]-a[10])+(a[8]-a[11])*(a[8]-a[11])+(a[9]-a[12])*(a[9]-a[12]))) =abs(sqrt ((a[10]-a[1])*(a[10]-a[1])+(a[11]-a[2])*(a[11]-a[2])+(a[12]-a[3])*(a[12]-a[3])))and
(abs(sqrt ((a[13]-a[16])*(a[13]-a[16])+(a[14]-a[17])*(a[14]-a[17])+(a[15]-a[18])*(a[15]-a[18]))) = abs(sqrt ((a[13]-a[16])*(a[13]-a[16])+(a[14]-a[17])*(a[14]-a[17])+(a[15]-a[18])*(a[15]-a[18]))) and
(abs(sqrt ((a[13]-a[16])*(a[13]-a[16])+(a[14]-a[17])*(a[14]-a[17])+(a[15]-a[18])*(a[15]-a[18]))) =abs(sqrt ((a[16]-a[19])*(a[16]-a[19])+(a[17]-a[20])*(a[17]-a[20])+(a[18]-a[21])*(a[18]-a[21]))) and
(abs(sqrt ((a[16]-a[19])*(a[16]-a[19])+(a[17]-a[20])*(a[17]-a[20])+(a[18]-a[21])*(a[18]-a[21]))) =abs (sqrt ((a[19]-a[22])*(a[19]-a[22])+(a[20]-a[23])*(a[20]-a[23])+(a[21]-a[24])*(a[21]-a[24]))) and
(abs(sqrt ((a[19]-a[22])*(a[19]-a[22])+(a[20]-a[23])*(a[20]-a[23])+(a[21]-a[24])*(a[21]-a[24]))) =abs(sqrt ((a[22]-a[13])*(a[22]-a[13])+(a[23]-a[14])*(a[23]-a[14])+(a[24]-a[15])*(a[24]-a[15]))) and
(abs(sqrt ((a[22]-a[13])*(a[22]-a[13])+(a[23]-a[14])*(a[23]-a[14])+(a[24]-a[15])*(a[24]-a[15])))=abs(sqrt ((a[13]-a[1])*(a[13]-a[1])+(a[14]-a[2])*(a[14]-a[2])+(a[15]-a[3])*(a[15]-a[3]))) and
(abs(sqrt ((a[13]-a[1])*(a[13]-a[1])+(a[14]-a[2])*(a[14]-a[2])+(a[15]-a[3])*(a[15]-a[3]))) = abs(sqrt ((a[16]-a[4])*(a[16]-a[4])+(a[17]-a[5])*(a[17]-a[5])+(a[18]-a[6])*(a[18]-a[6])))and
(abs(sqrt ((a[16]-a[4])*(a[16]-a[4])+(a[17]-a[5])*(a[17]-a[5])+(a[18]-a[6])*(a[18]-a[6])))= abs(sqrt ((a[19]-a[1])*(a[19]-a[7])+(a[20]-a[8])*(a[20]-a[8])+(a[21]-a[9])*(a[21]-a[9]))) and
(abs(sqrt ((a[19]-a[1])*(a[19]-a[7])+(a[20]-a[8])*(a[20]-a[8])+(a[21]-a[9])*(a[21]-a[9]))) = abs(sqrt ((a[22]-a[10])*(a[22]-a[10])+(a[23]-a[11])*(a[23]-a[11])+(a[24]-a[12])*(a[24]-a[12])))) then writeln ('yes');
Readln;
программа выясняет, является ли фигура с задаными 24 координатами кубом
+139
out[0] = str[0] > str[1] && str[0] > str[2] ? (out[1] = str[1] > str[2] ? (out[2] = str[2],str[1]) : (out[2] = str[1],str[2]) ,str[0]) : (str[1] > str[2] ? (out[1] = str[0] > str[2] ? (out[2] = str[2],str[0]): (out[2] = str[0],str[2]),str[1]) :(out[1] = str[0] > str[1] ? (out[2] = str[1],str[0]): (out[2] = str[0],str[1]),str[2]) );
Сортируем 3 символа.
+4
int DataBase::garbageCollector(string filename){
fstream from(filename.c_str());
fstream from0((filename+".index").c_str());
Index x;
Data d;
char *a/*,*b*/;
int oldpos = 0 ;
bool done = false;
from.seekg(0,ios::end);
int dbend = static_cast<int>(from.tellp());
from0.seekg(0,ios::end);
int indexend = static_cast<int>(from0.tellp());
if(dbend == BlockSize || indexend == IndexSize){
from.close();
from0.close();
return 0;
}
from.seekg(0,ios::beg);
from0.seekg(0,ios::beg);
while(true){
from0 >> x;
if(from0.eof())break;
if(!x.Num()){
int count = dbend - x.Pointer() - BlockSize;
int count0 = indexend - (static_cast<int>(from0.tellp())+1);
from.seekg(x.Pointer()+BlockSize);
a = new char[count];
from.read(a,count);
from.seekp(x.Pointer());
from.write(a,count);
delete a;
a = new char[count0];
from0.seekp(1,ios::cur);
int test = from0.tellp();
from0.read(a,count0);
from0.clear();
from0.seekp(indexend - count0 - IndexSize,ios::beg);
test = from0.tellp();
from0.write(a,count0);
test = from0.tellp();
delete a;
ofstream to("tmp.base",ios::trunc),to0("tmp.index",ios::trunc);
a = new char[dbend - BlockSize];
from.seekg(0,ios::beg);
from.read(a,dbend - BlockSize);
to.write(a,dbend - BlockSize);
delete a;
a = new char[indexend - IndexSize];
from0.seekg(0,ios::beg);
test = from0.tellp();
from0.read(a,indexend - IndexSize);
to0.write(a,indexend - IndexSize);
delete a;
from.close();
from0.close();
if(remove(filename.c_str()) || rename("tmp.base",filename.c_str())) return -1;
if(remove((filename+".index").c_str()) || rename("tmp.index",(filename+".index").c_str())) return -1;
oldpos = indexend - count0 - IndexSize;
done = true;
break;
}
}
if(done){
from0.open((filename+".index").c_str());
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() > static_cast<unsigned>((oldpos/23)*BlockSize) ){
x.Pointer(x.Pointer()-BlockSize);
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
}
else{
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
}
}
}
return 0;
}
Собираем пустые блоки
+6
int DataBase::split(fstream& from,fstream& from0,unsigned int p){
int pos0 = static_cast<int>(from.tellp());
char *a,*b;
Data d,d0;
Index x,x0;
from.clear();
from.seekp(0,ios::end);
int PosEnd = static_cast<int>(from.tellp());
PosEnd -=static_cast<int>(p);
a = new char[PosEnd];
from.seekp(p,ios::beg);
from.read(a,PosEnd);
from.seekp(p+BlockSize,ios::beg);
from.write(a,PosEnd);
from.seekp(p+BlockSize,ios::beg);
b = a+5*RecordSize;
from.write(b,RecordSize*5);
for (int i = 0; i < 5; ++i){
from << d;
}
from.seekp(p+RecordSize*5,ios::beg);
for (int i = 0; i < 5; ++i){
from << d;
}
from.seekg(p+RecordSize*4);
from >> d;
int newmax = d.Id();
from0.seekp(0,ios::end);
int indexend =static_cast<int>(from0.tellp());
from0.seekg(0,ios::beg);
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() == p){
int oldpos = static_cast<int>(from0.tellp());
oldpos++;
int count = indexend - oldpos;
char *c = new char[count];
from0.seekg(1,ios::cur);
from0.read(c,count);
from0.seekp(oldpos,ios::beg);
x0.Max(x.Max());
x0.Num(5);
x0.Pointer(p + BlockSize);
from0 << x0;
from0.write(c,count);
from0.seekp(oldpos - IndexSize,ios::beg);
x.Max(newmax);
x.Num(5);
from0 << x;
delete c;
from.clear();
from0.seekp(0,ios::beg);
break;
}
}
from.clear();
bool first = false;
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() > p ){
if(!first){
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
first = true;
continue;
}
x.Pointer(x.Pointer()+BlockSize);
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
}
else{
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
}
}
from.clear();
from.seekp(pos0);
delete a;
//delete b;
return 0;
}
Нарезаем
−126
#!/usr/bin/ruby
# encoding=utf8
size=2
start=0
c=['Н', 'Н' ,'Н' ,'Н' ,'Н','Н','Н','Н','Н','Н','Н','Н','Н','Н']
code_dictionary=Array.new()
begin_size_code_dictionary=Array.new()
end_string=String.new()
code_dictionary=c.uniq.to_a
decode_dictionary=c.uniq.to_a
for i in 0...code_dictionary.size
begin_size_code_dictionary[i]=i
end
c.size.times{
if !code_dictionary.include?(c[start,size].to_s)#Comparation
code_dictionary.push(c[start,size].to_s.chomp)
start=start+(code_dictionary.last.size)/2-1
size=2
else
size+=1;
end
}
end_code=Array.new(code_dictionary.size)
for i in begin_size_code_dictionary.size...code_dictionary.size
end_code[i]=code_dictionary.index(code_dictionary[i].chop.chop)+1
end_string+=code_dictionary[i].chop.chop
end
if (c.size>(end_string.size)/2)
end_code.push(code_dictionary.index(c.last)+1)
end
end_code=end_code.compact
puts code_dictionary
puts "Input: "+c.join
puts "Output: "+end_code.join
puts "Compression coef= "+((c.size-end_code.size)*100/c.size).to_s+"%"
end_decode = Array.new(end_code.size)
def ololo(end_code,decode_dictionary,end_decode)
count=true
end_code.each{|elem|
if elem <= decode_dictionary.size && count == true
end_decode[end_code.index(elem)]=decode_dictionary[elem-1]
else
count = false
end
}
end
puts decode_dictionary.size
def ololo2(end_code,decode_dictionary,end_decode)
if decode_dictionary.size == 1
decode_dictionary[1]=Array.new
decode_dictionary[1].push(decode_dictionary[0])
decode_dictionary[1].push(decode_dictionary[0])
decode_dictionary[1]=decode_dictionary[1].join
end
temp_array=end_decode.compact.to_s
start =0
size = 2
temp_array.size.times{
if !decode_dictionary.include?(temp_array[start,size*2])
decode_dictionary.push(temp_array[start,size*2])
start=start+decode_dictionary.last.size-2
size=2
else
size+=1
end }
end
count=true
ololo(end_code,decode_dictionary,end_decode)
ololo2(end_code,decode_dictionary,end_decode)
ololo(end_code,decode_dictionary,end_decode)
c4=end_decode.size
while end_decode.compact.size < end_decode.size && c4 > 0
ololo2(end_code,decode_dictionary,end_decode)
ololo(end_code,decode_dictionary,end_decode)
c4-=1
end
for i in 0...end_decode.size
if end_decode[i] == nil
end_decode[i]=decode_dictionary[end_code[i]-1]
end
end
puts "Decoded: "+end_decode.to_s
Кривой LZW
+10
void ImageArea::saveConf(bool def)
{
static bool fp = true;
static QString filename = QString("default.conf");
if(!def){
filename = QFileDialog::getSaveFileName(this, tr("Save config"), "", tr("Config files (*.conf)"));
if(fp){
QFile file(filename);
if(file.open(QFile::WriteOnly)){
QTextStream str(&file);
str << crop[0].x() << " " << crop[0].y() << "\n";
str << crop[1].x() << " " << crop[1].y() << "\n";
str << square[0].x() << " " << square[0].y() << "\n";
str << square[1].x() << " " << square[1].y() << "\n";
str << square[2].x() << " " << square[2].y() << "\n";
QMessageBox::information(this, tr("Next step"), tr("Put 3 points then press Save again"));
}else{
QMessageBox::warning(this, tr("Error"), tr("Can not open a file"));
}
fp = false;
}else{
QFile file(filename);
if(file.open(QFile::Append)){
QTextStream str(&file);
str << square[0].x() << " " << square[0].y() << "\n";
str << square[1].x() << " " << square[1].y() << "\n";
str << square[2].x() << " " << square[2].y() << "\n";
}else{
QMessageBox::warning(this, tr("Error"), tr("Can not open a file"));
}
fp = true;
}
}else{
QFile file(filename);
if(file.open(QFile::WriteOnly)){
QTextStream str(&file);
str << conf.crop[0].x() << " " << conf.crop[0].y() << "\n";
str << conf.crop[1].x() << " " << conf.crop[1].y() << "\n";
str << conf.square[0].x() << " " << conf.square[0].y() << "\n";
str << conf.square[1].x() << " " << conf.square[1].y() << "\n";
str << conf.square[2].x() << " " << conf.square[2].y() << "\n";
str << conf.square0[0].x() << " " << conf.square0[0].y() << "\n";
str << conf.square0[1].x() << " " << conf.square0[1].y() << "\n";
str << conf.square0[2].x() << " " << conf.square0[2].y() << "\n";
}
}
}
Сохраняем конфиг в джва захода.
+13
if(ortho){
if( abs(e->x() - line.p1().x() ) * 2 < abs( e->y() - line.p1().y() ) ){
y = e->y();
x = line.p1().x();
}else if(abs(e->x() - line.p1().x() ) > 2 * abs( e->y() - line.p1().y() )){
x = e->x();
y = line.p1().y();
}else if(abs(e->x() - line.p1().x() ) * 2 > abs( e->y() - line.p1().y() ) &&
abs(e->x() - line.p1().x() ) < abs( e->y() - line.p1().y() )){
if((e->x() < line.p1().x() && e->y() < line.p1().y()) || (e->x() > line.p1().x() && e->y() < line.p1().y())){
x = e->x();
y = line.p1().y() - abs(line.p1().x() - e->x());
}else if((e->x() > line.p1().x() && e->y() > line.p1().y()) || (e->x() < line.p1().x() && e->y() > line.p1().y())){
x = e->x();
y = line.p1().y() + abs(line.p1().x() - e->x());
}
}else if(abs(e->x() - line.p1().x() ) < 2 * abs( e->y() - line.p1().y() ) &&
abs(e->x() - line.p1().x() ) > abs( e->y() - line.p1().y() )){
if((e->x() < line.p1().x() && e->y() < line.p1().y()) || (e->x() < line.p1().x() && e->y() > line.p1().y())){
y = e->y();
x = line.p1().x() - abs(line.p1().y() - e->y());
}else if((e->x() > line.p1().x() && e->y() > line.p1().y()) || (e->x() > line.p1().x() && e->y() < line.p1().y())){
y = e->y();
x = line.p1().x() + abs(line.p1().y() - e->y());
}
}else{
x = e->x();
y = e->y();
}
+29
//thirteen
Cluster cl;
Cluster empty;
I--;
if(distances.size()){
for (int i = 0; i < (Lmax < distances.size() ? Lmax : distances.size()); ++i){
cl.X(( clusters.at(distances.at(i).first.first).X()*clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).X()*clusters.at(distances.at(i).first.second).Points().size())/(clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).Points().size()));
cl.Y(( clusters.at(distances.at(i).first.first).Y()*clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).Y()*clusters.at(distances.at(i).first.second).Points().size())/(clusters.at(distances.at(i).first.first).Points().size() + clusters.at(distances.at(i).first.second).Points().size()));
if(clusters.at(distances.at(i).first.second).Number() != -1 && clusters.at(distances.at(i).first.first).Number() != -2){
cl.Points() = clusters.at(distances.at(i).first.second).Points();
clusters.at(distances.at(i).first.second) = cl;
clusters.at(distances.at(i).first.second).Number(-1);
for (std::vector<Point>::iterator j = clusters.at(distances.at(i).first.first).Points().begin(); j != clusters.at(distances.at(i).first.first).Points().end(); ++j)
{
clusters.at(distances.at(i).first.second).Points().push_back(*j);
}
clusters.at(distances.at(i).first.first) = empty;
n_c--;
}
}
for (std::vector<Cluster>::iterator i = clusters.begin(); i != clusters.end(); ++i){
if(i->Number() == -2){
i = clusters.erase(i);
}
i->Number(i - clusters.begin());
if(I)i->Points().clear();
if(i == clusters.end())break;
}
}
//fourteen
Кусок алгоритма isodata
+16
for(int i=0;i<World::size;i++)
{
for(int u=0;u<World::size;u++)
{
//Задаётся зерно для генерации случайных чисел
srand(GetTickCount()*i*u);
//Задаются случайные значения всем точкам от 0*0.1-10, до 100*0.1-10
World::data[i][u]=(rand()%100)*0.1f-10.0f;
}
}
http://habrahabr.ru/post/183986/