- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
std::queue<char *> outQueue2;
std::lock_guard<std::mutex> lock(mtx);
mtx.lock();
if (outQueue.size() > 0) {
std::swap(outQueue2, outQueue);
outQueue = {};
}
std::lock_guard<std::mutex> unlock(mtx);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
std::queue<char *> outQueue2;
std::lock_guard<std::mutex> lock(mtx);
mtx.lock();
if (outQueue.size() > 0) {
std::swap(outQueue2, outQueue);
outQueue = {};
}
std::lock_guard<std::mutex> unlock(mtx);
со слов автора:
у меня 2 исходящие очереди
в одну соседний поток ложит
потом приходит тик
врубает симафор
копирует по-бырому очередь
и чистит её
дальше отпускает поток
чтобы не ждать
пока всё отправится
и спокойно в соседнем потоке уже начинает BYtestream...
и всё такое
разьве не так делают в домах парижу?
0
#include "stdafx.h"
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<fstream>
#include<iomanip>
#include<algorithm>
//#include<algorithm>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
multimap<string, int> mp;
multimap<string, int>::iterator it;
multimap<string, int>::iterator mit;
pair<multimap<string,int>::iterator, multimap<string, int>::iterator> pt;
set<int>nset;
string word;
char c = ' ';
char s[256];
fstream inOut;
inOut.open("text.txt", ios::in);
for (int i = 1; i < 500; i++) {
inOut.getline(s, 256);
char* pch;
pch = strtok(s, " ,-:");
while (pch != NULL) {
word = string(pch);
transform(word.begin(), word.end(), word.begin(), ::tolower);
mp.insert(pair <string, int>(word, i));
//cout « pch «'\t'«i« endl;
pch = strtok(NULL, " ,-:");
}
}
inOut.close();
set<string>set;
string tmp;
for (mit = mp.begin(); mit != mp.end(); mit++) {
tmp = (*mit).first;
if (set.find(tmp) != set.end()) {
continue;
}
else {
set.insert(tmp);
cout<<setw(15) << tmp << '\t';
pt = mp.equal_range(tmp);
for (it = pt.first; it != pt.second; ++it) {
nset.insert(it->second);
}
//cout << nset.size() << " ";
for (it = pt.first; it != pt.second; ++it) {
cout << it->second << ' ';
}
nset.clear();
cout << endl;
}
}
system("pause");
return 0;
}
Программа считывает слова сортирует и выдаёт все номера строк где данное слово встречается
−1
#include <stdio.h>
#include <stdlib.h>
int * ptr;
int * getptr()
{
puts("getptr");
return ptr;
}
int jump()
{
puts("jump");
ptr = (int*)malloc(sizeof(int));
return 1337;
}
int main()
{
ptr = (int*)malloc(sizeof(int));
*ptr = 0;
*( getptr() ) = 1;
printf( "*ptr = %i\n\n", *ptr );
*( getptr() ) = (jump(), 100);
printf( "*ptr = %i\n\n", *ptr );
*( getptr() ) = jump();
printf( "*ptr = %i\n\n", *ptr );
return 0;
}
ШИКАРНО:
Start
getptr
*ptr = 1
jump
getptr
*ptr = 100
getptr
jump
*ptr = 0
0
Finish
+2
https://m.reddit.com/r/cpp/comments/4pmlpz/what_the_iso_c_committee_added_to_the_c17_working/
Мне остаётся только спросить:
+5
++ ++i;
+5
\message{Russian hyphenation patterns by D. Vulis,}
\message{modified by M.Vorontsova and S.Lvovski.}
\message{Version date: 24.02.96}
--- неинтересная часть пропущена ---
{
\lccode`\a=`\м
\lccode`\b=`\г
\lccode`\c=`\у
\lccode`\d=`\е
\lccode`\e=`\с
\lccode`\f=`\х
\lccode`\g=`\у
\lccode`\h=`\к
\lccode`\i=`\г
\lccode`\j=`\х
\lccode`\k=`\м
\lccode`\l=`\н
\lccode`\n=`\ъ
\lccode`\o=`\з
\lccode`\p=`\й
\lccode`\q=`\ю
\lccode`\r=`\д
\lccode`\s=`\у
\lccode`\t=`\д
\lccode`\u=`\х
\lccode`\v=`\я
\lccode`\w=`\ы
\lccode`\x=`\z
\lccode`\y=`\ь
\lccode`\z=`\ч
\lowercase{
\patterns{
6jcp. 6usv. 6fgq. 6ucdk.
}
}
}
Отрывок из образцов переноса слов для TeX'а. Авторы постеснялись написать открытым текстом четыре образца (строка 35), поэтому зашифровали их простой подстановкой.
Читателю предлагается расшифровать эти образцы и догадаться, чего испугались авторы.
+2
.section-cart .table .th1.th1,
.section-cart .table .th2.th1,
.section-cart .table .th3.th1,
.section-cart .table .th4.th1 {
width: 575px;
}
.section-cart .table .th1.th2,
.section-cart .table .th2.th2,
.section-cart .table .th3.th2,
.section-cart .table .th4.th2 {
width: 285px;
}
.section-cart .table .th1.th3,
.section-cart .table .th2.th3,
.section-cart .table .th3.th3,
.section-cart .table .th4.th3 {
width: 250px;
}
.section-cart .table .th1.th1,
.section-cart .table .th2.th2,
.section-cart .table .th3.th3,
.section-cart .table .th4.th4 {
width: 250px;
}
.section-cart .table .td1,
.section-cart .table .td2,
.section-cart .table .td3,
.section-cart .table .td4,
.section-cart .table .td5,
.section-cart .table .td6 {
display: inline-block;
vertical-align: middle;
height: 215px;
border-bottom: 1px solid #d1d1d1;
}
.section-cart .table .td1.td1,
.section-cart .table .td2.td1,
.section-cart .table .td3.td1,
.section-cart .table .td4.td1,
.section-cart .table .td5.td1,
.section-cart .table .td6.td1 {
width: 245px;
line-height: 215px;
text-align: center;
}
.section-cart .table .td1.td1 img,
.section-cart .table .td2.td1 img,
.section-cart .table .td3.td1 img,
.section-cart .table .td4.td1 img,
.section-cart .table .td5.td1 img, {
.section-cart .table .td5.td1 img {
display: inline-block;
vertical-align: middle;
}
.section-cart .table .td1.td2,
.section-cart .table .td2.td2,
.section-cart .table .td3.td2,
.section-cart .table .td4.td2,
.section-cart .table .td5.td2 {
padding-left: 30px;
line-height: 215px;
padding-right: 25px;
width: 355px;
}
.section-cart .table .td1.td2 > span,
.section-cart .table .td2.td2 > span,
.section-cart .table .td3.td2 > span,
.section-cart .table .td4.td2 > span,
.section-cart .table .td5.td2 > span {
line-height: normal;
display: inline-block;
vertical-align: middle;
}
.section-cart .table .td1.td2 .title,
.section-cart .table .td2.td2 .title,
.section-cart .table .td3.td2 .title,
.section-cart .table .td4.td2 .title,
.section-cart .table .td5.td2 .title {
color: #181415;
font-size: 22px;
padding-bottom: 20px;
}
.section-cart .table .td1.td2 .opts,
.section-cart .table .td2.td2 .opts,
.section-cart .table .td3.td2 .opts,
.section-cart .table .td4.td2 .opts,
.section-cart .table .td5.td2 .opts {
font-size: 16px;
color: #636363;
line-height: 24px;
}
.section-cart .table .td1.td2 .opts b,
.section-cart .table .td2.td2 .opts b,
.section-cart .table .td3.td2 .opts b,
.section-cart .table .td4.td2 .opts b,
.section-cart .table .td5.td2 .opts b {
display: inline-block;
padding-right: 10px;
color: #181415;
}
Вот так вот строим обычную табличку.
+11
public class Solution
{
public static void main(String[] args)
{
int a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, i = 8, j = 9, k = 10;
System.out.println( + ( a + b ));
System.out.println( + ( a + b + c ));
System.out.println( + ( a + b + c + d ));
System.out.println( + ( a + b + c + d + e ));
System.out.println( + ( a + b + c + d + e + f ));
System.out.println( + ( a + b + c + d + e + f + g ));
System.out.println( + ( a + b + c + d + e + f + g + i ));
System.out.println( + ( a + b + c + d + e + f + g + i + j ));
System.out.println( + ( a + b + c + d + e + f + g + i + j + k ));
}
}
Вывести на экран сумму чисел от 1 до 10 построчно.
+153
Оторвемся чуть от политики.
Вопрос у меня такой.
Надо мне зарегать около полу сотни доменных имен. Вот собственно вопрос кто знает регистратор имен. подешевле и что бы мог регать имена из файлика например.
Сразу же улучшу
https://codebabes.com/
+57
typedef deque<uint8_t> bn;
#define cat2(b,e) b##e
#define cat(b,e) cat2(b,e)
#define fsi(i,s,e) for(size_t i(s), cat(i,cat(_fsi_end_,__LINE__))(e); i<cat(i,cat(_fsi_end_,__LINE__)); ++(i))
void ml10(bn& n){
n.push_front(0);
}
uint8_t ni(const bn& n, size_t i){
if(n.size()<=i)
return 0;
else
return n[i];
}
size_t ms(const bn& n1, const bn& n2){
return (max) (n1.size(), n2.size());
}
void pb(uint8_t b1, uint8_t b2, uint8_t lc, uint8_t& r, uint8_t& c){
uint8_t tr = (b1+b2+lc);
r = tr & 1;
c = !!(tr & 2);
}
bn bi(bn n){
reverse(n.begin(), n.end());
return n;
}
bn pl(const bn& n1, const bn& n2){
bn r;
uint8_t c=0,br=0;
fsi(i,0,ms(n1, n2)){
pb(ni(n1,i),ni(n2,i),c,br,c);
r.push_back(br);
}
if (c)
r.push_back(c);
return r;
}
bn ml(bn n1, const bn& n2){
bn r;
fsi(i,0,n2.size()){
if(n2[i])
r=pl(r,n1);
ml10(n1);
}
return r;
}
У меня к вам вопрос парни.
В нашем отделе взяли олимпиадника. За ним не следили. Он написал много кода и ушел в гугл.
Как бы за ним теперь код поправить? Хотябы конструкции языка типа for вернуть вместо например fsi?
Код не из проекта. но его. В проекте похожий и даже хуже.
Нужно типа утилиты препроцессор крестов для части макросов (все разворачивать макросы или инклудить хедеры очевидно нельзя).