20.12.2017, 12:30
(
Последний раз редактировалось OneDay; 19.04.2018 в 10:18.
)
PHP код:
StringToNumber(const string[]) {
new i = 0;
new neg = 1;
while (0 < string[i] <= ' ') i++;
if (string[i] == '+') i++;
else if (string[i] == '-') neg = -1, i++;
if (!('0' <= string[i] <= '9')) return 0;
new upper = 0;
new lower = 0;
for ( ; ; i++) {
switch (string[i]) {
case '0': lower = lower * 10;
case '1': lower = lower * 10 + 1;
case '2': lower = lower * 10 + 2;
case '3': lower = lower * 10 + 3;
case '4': lower = lower * 10 + 4;
case '5': lower = lower * 10 + 5;
case '6': lower = lower * 10 + 6;
case '7': lower = lower * 10 + 7;
case '8': lower = lower * 10 + 8;
case '9': lower = lower * 10 + 9;
case '.', ',': {}
case 'k', 'K': upper = (upper + lower) * 1000, lower = 0;
case 'm', 'M': upper = (upper + lower) * 1000000, lower = 0;
case 'g', 'G': upper = (upper + lower) * 1000000000, lower = 0;
default: break;
}
}
return (upper + lower) * neg;
}
10 = 10
10k = 10000
10k1 = 10001
11k11 = 11011
10kk = 10000000
10M = 10000000
1k1 = 1001
1k1k1 = 1001001