c++:
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
int sum=0;bool f=0;
for(int i=0;i<s.size();i++)
{
if(isalpha(s[i]))
{
s[i]=tolower(s[i]);
sum+=s[i]-'a'+1;
}else
{
f=1;
}
}
if(f==1)
{
if(s.size()==1&&s[0]=='0')
{
return 0;
}else
{
cout<<"Fail"<<endl;
}
}
else
{
cout<<sum<<endl;
}
}
return 0;
}AC
c:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char s[100];
while (scanf("%s", s) != EOF) {
int sum = 0;
int f = 0;
for (int i = 0; s[i] != '\0'; i++) {
if (isalpha(s[i])) {
s[i] = tolower(s[i]);
sum += s[i] - 'a' + 1;
} else {
f = 1;
}
}
if (f == 1) {
if (strlen(s) == 1 && s[0] == '0') {
return 0;
} else {
printf("Fail\n");
}
} else {
printf("%d\n", sum);
}
}
return 0;
}RE系統呼叫了 abort 函式! *** stack smashing detected ***: terminated Aborted (core dumped)
char s[100];
不夠大吧,題目說最多200字