forked from avidit11/codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_of_string.cpp
More file actions
41 lines (40 loc) · 1023 Bytes
/
sum_of_string.cpp
File metadata and controls
41 lines (40 loc) · 1023 Bytes
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
#include<bits\stdc++.h>
using namespace std;
int main()
{
string a;
getline(cin,a);
a=a+" ";
int sum=0;
string w="";
for(int i=0;a[i]!=0;i++){
if(a[i]!=' '){
w=w+a[i];
}
else{
if(w.size()%2==0){
for(int j=0;j<w.size()/2;j++){
int x=a[j]-a[w.size()-j-1];
if(x>=0){
sum=sum+x;
}
else
sum=sum-x;
} }
else if(w.size()%2!=0){
for(int j=0;j<w.size()/2;j++){
int x=a[j]-a[w.size()-j-1];
if(x>=0){
sum=sum+x;
}
else
sum=sum-x;
}
sum=sum+a[w.size()/2]-96;
}
w="";
}
}
cout<<sum;
return 0;
}