-
+30
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
class MakeBARCODE
{
public static string MakeEAN13(long prefix, long code)
{
//В случае если префикс или код слишком большие то будет выдана ошибка:
string result = "ERROR_TOOLONG";
if ((prefix < 100) && (code < 10000000000))
{
//Получаем строку символов (цифр).
long all_code = prefix * 100000000000 + code;
string nabor = all_code.ToString();
//Сумма по чётным позициям.
int count_chet = int.Parse(nabor[1].ToString()) + int.Parse(nabor[3].ToString()) + int.Parse(nabor[5].ToString()) + int.Parse(nabor[7].ToString()) + int.Parse(nabor[9].ToString()) + int.Parse(nabor[11].ToString());
//Сумма по нечётным позициям.
int count_nechet = int.Parse(nabor[0].ToString()) + int.Parse(nabor[2].ToString()) + int.Parse(nabor[4].ToString()) + int.Parse(nabor[6].ToString()) + int.Parse(nabor[8].ToString()) + int.Parse(nabor[10].ToString());
//Контрольная сумма и контрольный разряд.
int control_summ = count_chet * 3 + count_nechet;
int ostatok = control_summ % 10;
if (!(ostatok == 0))
{
ostatok = 10 - ostatok;
}
result = nabor + ostatok.ToString();
}
return result;
}
}
Наткнулся сегодня в интернетах на алгоритм расчета контрольной суммы EAN.
kovyl2404,
01 Сентября 2012
-
+32
- 1
static_cast<SomeOtherClass>(this)->SomeMethod();
Чуваки лучше знают, что у них в this
bazhenovc,
31 Августа 2012
-
+26
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
result.push_back(TVector<2>
(
(A-√(D))/C,
(E-Line.K()*√(D))/C
));
result.push_back(TVector<2>
(
(A+√(D))/C,
(E+Line.K()*√(D))/C
));
LispGovno,
31 Августа 2012
-
+42
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
std::string loc =
( {
const char *str = "";
switch (location) {
case Net::HANDSHAKE_TIMEOUT:
str = _(" due to handshake timeout");
break;
case Net::RECV_HANDSHAKE:
str = _(" while waiting for handshake");
break;
case Net::HANDSHAKE_DATA:
str = _(" due to unsupported handshake data");
break;
case Net::HANDSHAKE_AUTH:
str = _(" while parsing handshake data");
break;
case Net::WAIT_DEVICE:
str = _(" while waiting for device");
break;
case Net::TRANSFER_DATA:
str = _(" while transferring data");
break;
}
str;
});
Я хуею с юных оптимизаторов.
gvy,
28 Августа 2012
-
+31
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
#include <iostream>
#include <tr1/functional>
using namespace std::tr1::placeholders;
struct I
{
int i;
};
struct S
{
int i;
I ii;
};
int main()
{
std::tr1::function<I& (S&)> pi = std::tr1::bind(&S::ii, _1);
std::tr1::function<std::tr1::reference_wrapper<I> (S&)> pri = std::tr1::bind(static_cast<std::tr1::reference_wrapper<I> (*)(I&)>(&std::tr1::ref<I>), std::tr1::bind(pi, _1));
std::tr1::function<int& (S&)> psi = std::tr1::bind(&I::i, std::tr1::bind(&std::tr1::reference_wrapper<I>::get, std::tr1::bind(pri, _1)));
S s = {1, {2}};
std::cout << psi(s) << std::endl;
psi(s) = 3;
std::cout << psi(s) << std::endl;
return 0;
}
Нашёл на RSDN, в теме о том, как получить указатель на член члена.
suc-daniil,
28 Августа 2012
-
+29
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
namespace NFlash
{
class TCommandMap
{
public:
typedef std::pair<NProtocolConsts::SCommands::E, pChar> TPair;
private:
std::vector<TPair> _commandMap;
public:
TCommandMap(void);
void appendCommand(TPair & Command);
void appendCommand(NProtocolConsts::SCommands::E, abstractString & Name);
const std::vector<TPair> & Names(void) const;
byte MaxCommandNameLength(void) const;
NProtocolConsts::SCommands::E GetCommandIndex(PChar Name) const;
};
void initCommandMaps(void);
}
Говногость,
24 Августа 2012
-
+39
- 1
- 2
- 3
- 4
- 5
- 6
extern const TSafeFloat Pi;//Не использовать до входа в main!!! Возможно она ещё не инициализированна!!!
//#define PI 3.14159265358979323846
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
Форматирование сохранено. Файл PiConsts.h
HaskellGovno,
24 Августа 2012
-
+27
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
// до рефакторинга
if(!y) {
if(!x) {
if(grid[pos+1] || grid[pos+fieldWidth])
ret = true;
} else if(x == fieldWidth - 1) {
if(grid[pos - 1] || grid[pos+fieldWidth])
ret = true;
} else {
if(grid[pos-1] || grid[pos+1] || grid[pos+fieldWidth])
ret = true;
}
} else if(y == fieldHeigth - 1) {
if(!x) {
if(grid[pos+1] || grid[pos-fieldWidth])
ret = true;
} else if(x == fieldWidth - 1) {
if(grid[pos - 1] || grid[pos-fieldWidth])
ret = true;
} else {
if(grid[pos-1] || grid[pos+1] || grid[pos-fieldWidth])
ret = true;
}
} else {
if(!x) {
if(grid[pos+1] || grid[pos+fieldWidth] || grid[pos-fieldWidth])
ret = true;
} else if(x == fieldWidth - 1) {
if(grid[pos - 1] || grid[pos+fieldWidth] || grid[pos+fieldWidth])
ret = true;
} else {
if(grid[pos - 1] || grid[pos+fieldWidth] || grid[pos-fieldWidth] || grid[pos + 1])
ret = true;
}
}
// после рефакторинга
bool ret = getGridPoint(x-1, y) || getGridPoint(x+1, y) || getGridPoint(x, y-1) || getGridPoint(x, y+1))
Код одного из моих друзей. Проверяет закрашена ли хотя бы одна клеточка вокруг указанной...
bormand,
20 Августа 2012
-
+19
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
??=include <iostream>
template <typename T> class TSingleton: public T
??<
public:
static T& instance(void)
??<
static T instance;
return instance;
??>;
??>;
class TOscillStatisticko
??<
protected:
TOscillStatisticko(void):_countNewInSmallPool(0), _countDeleteInSmallPool(0) ??<??>;
friend class TSingleton <TOscillStatisticko>;
private:
int _countNewInSmallPool;
int _countDeleteInSmallPool;
public:
void addCountNewInSmallPool(void)
??<
_countNewInSmallPool++;
??>
int countNewInSmallPool(void)
??<
return _countNewInSmallPool;
??>
??>;
typedef TSingleton <TOscillStatisticko> TOscillStatistic;
int main()
??<
TOscillStatistic::instance().addCountNewInSmallPool();
std::cout<<TOscillStatistic::instance().countNewInSmallPool()<<std::endl;
std::cout<<"ko"<<std::endl;
??>
http://ideone.com/dt9L9
Ладно, раз уж я так палюсь, то придется признаться: у меня просто сломалась клавиатура, потому сегодня пришлось написать немного странно...
Так вот вопрос:, почему, если закомментировать строку
friend class TSingleton <TOscillStatisticko>;
http://ideone.com/4WBGh
HaskellGovno,
20 Августа 2012
-
+38
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
const NMath::TLineEquation<> C_E_(C_, E_);
const NMath::TLineEquation<> D_A_(D_, A_);
const NMath::TVector<2> F_=C_E_.Intersection(D_A_);
TSafeFloat lpr=_state._safeDistance->Value()+_state._instrumentRadius->Value();
if((F_-B).Length()>lpr)
{
const NMath::TVector<2> F__=(D_+E_)/2.0;//F
//...
const NMath::TVector<2> TV=D_-E_;
const NMath::TVector<2> F___=PointAtDistance(B,TV,lpr, m90);//F*
const NMath::TVector<2> DEDir=rt90(F___-B, m90).Normalize()*10;
const NMath::TLineEquation<> DE(F___,F___+DEDir);
const NMath::TVector<2> E=DE.Intersection(C_E_);
const NMath::TVector<2> D=DE.Intersection(D_A_);
TpointerAnyCommand result;
result=new TLineCommand(CurrentCommand.SourceCommand(),E-C_,OnOffCorrectionEmpty);
_resultDestination.push(result);
result=new TLineCommand(CurrentCommand.SourceCommand(),D-E,OnOffCorrectionEmpty);
_resultDestination.push(result);
result=new TLineCommand(CurrentCommand.SourceCommand(),D_-D,OnOffCorrectionEmpty);
_resultDestination.push(result);
}
Говногость,
20 Августа 2012