-
Notifications
You must be signed in to change notification settings - Fork 0
/
String to Integer.cpp
73 lines (68 loc) · 1.74 KB
/
String to Integer.cpp
1
2
3
4
5
6
7
8
9
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
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <map>
using namespace std;
#define MAX 1000000
#define fr(x) freopen(x, "r", stdin)
#define pfi(x) printf("%d\n", x)
#define pfl(x) printf("%lld\n", x)
#define pff(x) printf("%f\n", x)
#define pfd(x) printf("%lf\n", x)
#define pfc(x) printf("%c\n", x)
#define pfs(x) printf("%s\n", x.c_str())
#define pfn() printf("\n")
#define sci(x) scanf("%d", &x)
#define scii(x, y) scanf("%d %d", &x, &y)
#define scl(x) scanf("%lld", &x)
#define scll(x, y) scanf("%lld %lld", &x, &y)
#define sclll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define scf(x) scanf("%f", &x)
#define scff(x, y) scanf("%f %f", &x, &y)
#define scd(x) scanf("%lf", &x)
#define scdd(x, y) scanf("%lf %lf", &x, &y)
#define scc(x) scanf(" %c", &x)
#define scs(x) getline(cin, x)
#define gt() getchar()
#define pb(x) push_back(x)
#define set(x, y) memset(x, y, sizeof(x))
int stringToInteger(string s, int *a) {
int i, j, k, l, x, y, n;
char ch[100];
n = s.size() + 1;
j = l = 0;
for(i=0; i<n; i++) {
if(s[i]==' ' || s[i]=='\0') {
ch[j] = '\0';
x = 0;
y = 1;
for(k=j-1; k>=0; k--) {
x+=(ch[k]-48)*y;
y*=10;
}
a[l++] = x;
j = 0;
}else {
ch[j++] = s[i];
}
}
return l;
}
int main()
{
string s;
int ar[1000], i, n;
while(getline(cin, s)) {
n = stringToInteger(s, ar);
for(i=0; i<n; i++) {
printf("%d: %d\n", i+1, ar[i]);
}
}
}