1.我統一將小寫改成大寫並檢查是否為英文字母
2.再將其轉為數字
#include <iostream>
#include<string>
using namespace std;
int check(string a)
{
int sum = 0, i = 0;
for (i = 0; i < a.length(); i++)
{
sum += a[i] - 64;
}
return sum;
}
int main()
{
string input;
int i, j;
bool eng = true;
while (getline(cin, input))
{
eng = true;
if (input == "0")
{
break;
}
for (i = 0; i < input.length(); i++)
{
if (input[i] >= 'A' && input[i] <= 'Z')
{
continue;
}
else if (input[i] >= 'a' && input[i] <= 'z')
{
input[i] -= 32;
}
else
{
eng = false;
break;
}
}
if (eng)
{
cout << check(input) << endl;
}
else
{
cout << "Fail" << endl;
}
}
return 0;
}