例: 全倒 X,-
沒中 -,6 -,/
2.把'-'換成0,方便運算。
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
void replaceD(string &s)
{
int i = 0;
while (i < s.length())
{
if (s[i] == ',')
s[i] = ' ';
else if (s[i] == '-')
s[i] = '0';
i++;
}
}
int main()
{
int sum = 0, score = 0, x = 0, y = 0;
int arr[10] = { 0 };
char n[21];
string s;
getline(cin, s);
replaceD(s);
stringstream ss(s);
while (ss >> n[x])
{
x++;
}
for (int i = 0; i < 19; i++)
{
score = 0;
if (i < 16)
{
if (n[i] == 'X')
{
score = 10;
if (n[i + 2] == 'X')
{
score += 10;
if (n[i + 4] == 'X')
score += 10;
else
score += n[i + 4] - '0';
}
else if (n[i + 3] == '/')
score += 10;
else
score += n[i + 2] - '0' + n[i + 3] - '0';
}
else if (n[i + 1] == '/')
{
score = 10;
if (n[i + 2] == 'X')
score += 10;
else
score += n[i + 2] - '0';
}
else
score = n[i] - '0' + n[i + 1] - '0';
i++;
}
else if (i == 16)
{
if (n[i] == 'X')
{
score = 10;
if (n[i + 2] == 'X')
{
score += 10;
if (n[i + 3] == 'X')
score += 10;
else
score += n[i + 3] - '0';
}
else if (n[i + 3] == '/')
score += 10;
else
score += n[i + 2] - '0' + n[i + 3] - '0';
}
else if (n[i + 1] == '/')
{
score = 10;
if (n[i + 2] == 'X')
score += 10;
else
score += n[i + 2] - '0';
}
else
score = n[i] - '0' + n[i + 1] - '0';
i++;
}
else
{
if (n[i] == 'X')
{
score += 10;
if (n[i + 1] == 'X')
{
score += 10;
if (n[i + 2] == 'X')
score += 10;
else
score += n[i + 2] - '0';
}
else if (n[i + 2] == '/')
score += 10;
else
score += n[i + 1] - '0' + n[i + 2] - '0';
}
else if (n[i + 1] == '/')
{
score += 10;
if (n[i + 2] == 'X')
score += 10;
else
score += n[i + 2] - '0';
}
else
score += n[i] - '0' + n[i + 1] - '0';
}
sum += score;
arr[y++] = sum;
}
for (int i = 0; i < 10; i++)
{
if (i > 0)
cout << ",";
cout << arr[i];
}
cout << endl;
return 0;
}
沒有留言:
張貼留言