- 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
int myAtoi(char *string)
{
int result = 0;
bool is_negative = false;
int num[10];
int s_lenght = strlen(string);
int mn = 1;
for(int i = s_lenght – 1; i >= 0; i–)
{
char chTemp = string[i];
switch(chTemp)
{
case ’0′:
num[i] = 0;
break;
case ’1′:
num[i] = 1;
break;
case ’2′:
num[i] = 2;
break;
case ’3′:
num[i] = 3;
break;
case ’4′:
num[i] = 4;
break;
case ’5′:
num[i] = 5;
break;
case ’6′:
num[i] = 6;
break;
case ’7′:
num[i] = 7;
break;
case ’8′:
num[i] = 8;
break;
case ’9′:
num[i] = 9;
break;
case ‘-’:
is_negative = true;
break;
}
if(!is_negative)
{
result += num[i] * mn;
mn *= 10;
}
}
if(is_negative)
result = -result;
return result;
}
gost 26.01.2017 10:06 # +1
Код - в мусорку, автора - в печь.
dxd 26.01.2017 10:08 # +2
gost 26.01.2017 14:02 # 0
inkanus-gray 26.01.2017 14:29 # 0
Psionic 26.01.2017 17:19 # +1
Steve_Brown 26.01.2017 18:03 # 0
inkanus-gray 26.01.2017 19:29 # 0
Psionic 27.01.2017 13:44 # +3
http://fishki.lv/uploads/posts/2014-06/1403873843_fotoprikoly_1.jpg
dm_fomenok 26.01.2017 15:35 # −14
guest 27.01.2017 23:57 # +1