-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCCM.cpp
129 lines (116 loc) · 1.95 KB
/
SCCM.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#define LEN 10
float convert(char *num,char *src)
{
float res=0.0f;
float ff=atof(num);
if(!strcmp("mile",src)||!strcmp("miles",src))
{
res=(ff*1609.344);
return res;
}
else if(!strcmp("yard",src)||!strcmp("yards",src))
{
res=ff*0.9144;
return res;
}
else if(!strcmp("inch",src)||!strcmp("inches",src))
{
res=ff*0.00254;
return res;
}
else if(!strcmp("foot",src)||!strcmp("feet",src))
{
res=ff*0.03048;
return res;
}
else if(!strcmp("fath",src)||!strcmp("faths",src))
{
res=ff*1.8288;
return res;
}
else
{
res=ff*201.17;
return res;
}
}
int main()
{
char *my_email="[email protected]";
char *u="m";
char *file_name="input.txt";
ifstream fin;
fin.open(file_name);
if(!fin.is_open())
{
printf("can not open %s\n",file_name);
fin.close();
exit(1);
}
ofstream fout("output.txt");
fout.setf(ios::fixed,ios::floatfield);
fout.precision(2);
fout<<my_email<<endl<<endl;
string line;
int count=0;
while(getline(fin,line,'\n'))
{
if(count<7)
{
count++;
continue;
}
if(NULL!=line.c_str())
{
char *line_str=new char[80];
memset(line_str,0,80);
strcpy(line_str,(char *)line.c_str());
int i=0;
char *p[LEN]={NULL};
char *buf=NULL;
buf=line_str;
char *inner_ptr=NULL;
while((p[i]=strtok_s(buf," ",&inner_ptr))!=NULL)
{
i++;
buf=NULL;
}
if(i<=0)
break;
if(i<=2)
{
float sum=0.0f;
sum=convert(p[0],p[1]);
fout<<sum<<" "<<u<<endl;
}
else
{
float sum=convert(p[0],p[1]);
for(int j=2;p[j]!=NULL;)
{
if(!strcmp(p[j],"+")&&isdigit(p[j+1][0]))
{
sum+=convert(p[j+1],p[j+2]);
j++;
}
else if(!strcmp(p[j],"-")&&isdigit(p[j+1][0]))
{
sum-=convert(p[j+1],p[j+2]);
j++;
}
else
j++;
}
fout<<sum<<" "<<u<<endl;
}
delete line_str;
}
}
fin.close();
fout.close();
return 0;
}