-
−1
- 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
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>
typedef std::ios_base& sibr;
typedef sibr (*StringType)(sibr);
int atoi_hod(const char a[], short int *offset)
{
short int numtype = (a[0]== '0')+((a[1]=='x')||(a[1]=='X'));
StringType st;
*offset = 0;
while(a[*offset]&&a[*offset]!='.') (*offset)=(*offset)+1;
switch (numtype)
{
case 0:
st = std::dec;
break;
case 1:
st = std::oct;
break;
case 2:
st = std::hex;
break;
}
int u;
std::istringstream(a)>>st>>u;
return u;
}
bool isIpv4String(const std::string &str)
{
size_t size = str.length();
bool result = size!=0;
if(result)
{
const char *c_str = str.c_str();
unsigned long int i = 0;
char sym;
do
{
sym = c_str[i++];
result = sym=='.'||(sym>='0'&&sym<='9')||!sym||(sym>='a'&&sym<='f')||(sym>='A'&&sym<='F')||sym=='x'||sym=='X';
}
while (sym&&result);
i = 0;
short int dotsOrTerm = 0, numbers = 0, offset;
while (result&&i<size)
{
int n = atoi_hod(&c_str[i], &offset);
result = n<256;
numbers += result;
i += offset;
result = result&&(c_str[i]=='.'||!c_str[i]);
i+=result;
dotsOrTerm += result;
}
result = (dotsOrTerm == 4)&&(numbers == 4);
}
return result;
}
int main()
{
std::string adress;
std::cin>>adress;
std::cout<<(isIpv4String(adress)?"TRUE":"FALSE")<<std::endl;
return 0;
}
По мотивам ГК #24055, наконец-то руки дошли.
Psionic,
09 Апреля 2018
-
0
- 1
- 2
- 3
- 4
- 5
try
{
// ... code ...
}
catch (ErrorResponseException& ex) { throw; }
Documenting-with-code?
Elvenfighter,
06 Апреля 2018
-
+1
- 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
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
bool kiemtraso(std::string &a,int i)
{
char N[4];
/* N[0]=a[i+0];
N[1]=a[i+1];
N[2]=a[i+2];*/
for(int n=0;n<3;n++)
{
N[n]=a[i+n];
}
if(atoi(N)>255) return 0;
return 1;
}
bool isIPv4Address(std::string inputString)
{
int n=inputString.length();
//3 dau cham=====================================гугл перевел: "3 часа ночи"
int dem=0;
for(int i=0;i<n;i++)
{
if(inputString[i]==46) dem++;
}
if(dem!=3) return 0;
//co hon mot ki tu==============================
if(inputString[0]==46||inputString[n-1]==46) return 0; //ki tu dau va cuoi khac dau cham
for(int i=1;i<inputString.length()-1;i++)
{
if(inputString[i]==46 && inputString[i+1] == 46) return 0;
}
//khong co chu cai=========================================
for(int i=0 ; i<n ; i++)
{
if (inputString[i]==47||inputString[i]<46||inputString[i]>57) return 0;
}
//2 so o giua nho hon 255===========================================
int sokitu;
for(int i=0; i<n-1 ; i++)
{
if(inputString[i]==46)
{
for(int j=i+1 ; j < n ; j++)
{
if(inputString[j]==46)
{
sokitu = j-i-1;
if(sokitu==3&&kiemtraso(inputString,i+1)==0) return 0;
if(sokitu>3) return 0;
break;
}
}
i++;
continue;
}
}
//so dau nho hon 255 =====================================
int kitudau;
int m=0;
for(int i=0;i<n;i++)
{
if(inputString[i]==46)
{
if (i==3 && kiemtraso(inputString,m)==0) return 0;
if (i>3) return 0;
break;
}
}
//so cuoi nho hon 255=======================================
for(int i=inputString.length()-1;i>0;i--)
{
if(inputString[i]==46)
{
if(inputString.length()-i-1==3 && kiemtraso(inputString,i+1)==0) return 0;
if (inputString.length()-i-1 > 3) return 0;
break;
}
}
return 1;
}
Проверяет, является ли введенная строка IP адресом.
Не мое
решение одного, судя по всему, вьетнамца.
Я пока не очень силен в алгоритмах, может это типа нормально, подскажите.
noserdan,
02 Апреля 2018
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
#include <stdlib.h>
#include <time.h>
#include <random>
#include <algorithm>
.........
.........
double
js::math_random_no_outparam(JSContext* cx)
{
if JSContext* == "Math.floor(Math.random() * (max - min + 1) + min)"
{
return Math.floor(Math.random() * (max - min + 1) + min);
}
return random_nextDouble(&cx->compartment()->rngState);
}
........
Доброго времени
хочу заставить Лису(FF) вычислять math функцию внутри браузера, а не через Windows (ADVAPI32.DLL Function36).
Но при компиляции измененного кода постоянно получаю ошибки.
Я конечно кривые коды пишу, но пытаюсь подстроиться под исходный С++.
...........................
в итоге не видит и не распознает ни рандом, ни фло, ни мат, ни джиэс контекст
Подскажите в каком направлении копать.
DrAli,
01 Апреля 2018
-
+3
- 1
http://www.bfilipek.com/2018/04/deprecating-pointers.html?m=1
Вот это удар в спину Царя! Он только начал нахваливать кресты,
как анскиллябры из комитета его предали.
CHayT,
01 Апреля 2018
-
0
- 1
https://twitter.com/jfbastien/status/979091653146193920
> 39 лойсов
> 13 ретвитов
Тьфу блять, хуже жаваскриптеров это крестушиное комьюнити.
subaru,
30 Марта 2018
-
+2
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
// We have to put a separate function with 'if constexpr' here as Visual Studio
// produces a false positive warning in a case of RegDstUInt == uint32
// (shifting uint32 left by 32 is an undefined behavior)
// See: https://developercommunity.visualstudio.com/content/problem/225040/c4293-false-positive-on-unreacheable-code.html
static RegDstUInt get_hi_part( RegDstUInt value)
{
// Clang-Tidy generates a false positive 'misc-suspicious-semicolon' warning
// on `if constexpr ()` with template
// LLVM bug 35824: https://bugs.llvm.org/show_bug.cgi?id=35824
if constexpr( (sizeof(RegDstUInt) > 4)
return value >> 32; // NOLINT
// GCC bug 81676 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81676
// Wrong warning with unused-but-set-parameter within 'if constexpr'
(void)(value);
return 0;
}
В попытке починить сборку в Visual Studio поломали GCC и Clang-Tidy.
pavelmips,
29 Марта 2018
-
+1
- 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
bool almostIncreasingSequence(std::vector<int> sq) {
bool b2 = true;
int s = sq.size();
if (s > 2) { // Последовательность меньше трех чисел дает истину.
int i = 1; // Проверка начинается со второго элемента.
int x = -1; // Для записи индекса элемента <= предыдущего, а еще "флаг".
while ((b2) && (i < s)) { // При нахождении 2-го лишнего происходит выход из цикла.
if (x != -1) { // Проверка "флага".
if (sq[i] <= sq[i - 1]){ // Сравнение с предыдущим элементом.
b2 = false; // Если условие истинно, то это уже второй элемент,
} // "конфликтующий" с предыдущим, следовательно, выход и "ложь".
if ((sq[i] <= sq[x - 1]) && (x != 1) && (sq[i - 1] <= sq[x - 2])) { // над этим условием я думал слишком долго
b2 = false; // Если элемент был "убран", индекс конфликтного
} // элемента записан в "x".
}
else { // Если условие ложно, то записываем индекс элемента, который
if (sq[i] <= sq[i - 1]) { // "конфликтует" с предыдущим.
x = i; // Нам не известно лишний он или нет.
}
}
i++;
}
}
return b2;
}
проверяет, можно ли убрать только один элемент из последовательности, чтобы она стала постоянно возрастающей.
noserdan,
28 Марта 2018
-
+2
- 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
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
//Шапка таблицы
cout << setw(10) <<char(218) <<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(194)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(194)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(191) <<endl;
cout <<setw(10) <<char(179) <<setw(10) <<"X" <<setw(10) <<char(179) <<setw(10) <<"F" <<setw(10)
<<char(179) <<setw(10) <<"G" <<setw(10) <<char(179) <<endl;
for (i = 0; i <= N; i++) {
x = A + i*h;
F = (x-1)*(x-1)*(x-1);
G = ((x+5)*(x+5)*(x+5))/(1+(sin(x)*sin(x)));
//Вывод в таблицу
cout <<setw(10) << char(195)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(197)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(197)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(180)<<endl;
cout << setw(10) << char(179) << setw(10)<< x << setw(10) << char(179) << setw(10)<< setprecision(5) << F << setw(10) << char(179) << setw(10) << setprecision(6) << G << setw(10) << char(179) << endl;
} //for (i = 0; i <= N; i++)
//Конец таблицы
cout << setw(10) << char(192)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(193)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(193)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)<<char(196)
<<char(217)<<endl;
eto pizdez prosto, ya lettau blyad
ETO_LABbl_DETKA,
26 Марта 2018
-
0
- 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
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
class NTPTime {
public:
static NTPTime getInvalidTime() { NTPTime t; t.setInvalid(); return t; }
public:
NTPTime() : m_Time(0) {}
NTPTime(const uint64_t time) : m_Time(time) {}
NTPTime(const uint32_t sec, const uint32_t frac)
: m_Time(0)
{
this->set(sec, frac);
}
NTPTime(const boost::posix_time::ptime& timestamp);
public: // Assignment operators
NTPTime& operator=(const uint64_t u) { m_Time = u; return *this; }
NTPTime& operator+= (const NTPTime& Q) { m_Time += Q.m_Time; return *this; }
NTPTime& operator-= (const NTPTime& Q) { m_Time -= Q.m_Time; return *this; }
public: // Cast operators
operator uint64_t() { return this->m_Time; }
public: // comparison operators
bool operator==(const NTPTime& other) const { return (m_Time == other.m_Time); }
bool operator!=(const NTPTime& other) const { return (m_Time != other.m_Time); }
bool operator>=(const NTPTime& other) const { return (m_Time >= other.m_Time); }
bool operator>(const NTPTime& other) const { return (m_Time > other.m_Time); }
bool operator<=(const NTPTime& other) const { return (m_Time <= other.m_Time); }
bool operator<(const NTPTime& other) const { return (m_Time < other.m_Time); }
public: // arithmetic operators
NTPTime operator+(const NTPTime& other) const
{
NTPTime result = *this;
result += other;
return result;
}
NTPTime operator-(const NTPTime& other) const
{
NTPTime result = *this;
result -= other;
return result;
}
public:
uint32_t getSeconds() const { return ((uint32_t)(m_Time >> 32));}
uint32_t getFracSeconds() const { return ((uint32_t)(m_Time & 0xFFFFFFFF));}
uint32_t getMilliseconds() const { const uint64_t t = 1000*m_Time ; return (uint32_t)((t>>32)&0xFFFFFFFF);}
uint32_t getMicroseconds() const { const uint64_t t = 125*m_Time/536871; return (uint32_t)(t&0xFFFFFFFF);}
void getTime_s_us(uint32_t& sec, uint32_t& us) const { sec = getSeconds(); us = getFracSeconds()/4295;}
uint64_t getTime(void) const {return m_Time;}
public:
/// set the time in seconds and microseconds (micros: 0..1000 0000)
///This routine uses the factorization: 2^32/10^6 = 4096 + 256 - 1825/32
void setTime_s_us(const uint32_t sec, const uint32_t us) { m_Time = ((uint64_t)sec<<32) | ((us<<12)-((us*1852)>>5)+(us<<8));}
void set(const uint64_t& u) {m_Time = u;}
void set(const uint32_t sec, const uint32_t frac)
{
m_Time = sec;
m_Time = m_Time<<32;
m_Time |= frac;
}
void setInvalid() { m_Time = uint64_t(NOT_A_DATE_TIME) << 32; }
/// 2^32/10^6 = 4096 + 256 - 1825/32
void setMicroseconds(const uint32_t u) { const uint64_t t = ((uint64_t)u * 1825) >> 5; m_Time = ((uint64_t)u << 12) + ((uint64_t)u << 8) - t;}
void setMicroseconds(const uint64_t u) { const uint64_t t = (u * 1825) >> 5; m_Time = (u << 12) + (u << 8) - t;}
void setMilliseconds(const uint32_t u) { m_Time = (uint64_t)u * 536870912 / 125;}
void addMilliseconds(const uint32_t u) { NTPTime t; t.setMilliseconds(u); *this += t;}
void addMicroseconds(const uint32_t u) { NTPTime t; t.setMicroseconds(u); *this += t;}
protected:
static double round(const double v);
private:
static const double secondFractionNTPtoNanoseconds;
static const double nanosecondsToSecondFractionNTP;
static const uint32_t NOT_A_DATE_TIME;
static const uint64_t NOT_A_DATE_TIME64;
static const boost::posix_time::ptime m_epoch;
protected:
uint64_t m_Time; ///< NTP time in 1/2^32 seconds (~233 ps)
}; // NTPTime
Чуть г-на и несколько комментов удалил, чтоб влезло. Чтоб понятно было, m_Time хранит время в единицах 1/2^32 сек.
elapidae,
22 Марта 2018