输入n个数字,用逗号分隔
处理过程如下:
char str[100];
char ch = '\0';
int i = 0;
vector<int> v;
int tmp = 0;
cin >> str;
while (str[i] != '\0'){
while (str[i]!='\0' && str[i] != ','){
tmp = tmp * 10 + str[i]-'0';
++i;
}
v.push_back(tmp);
if (str[i] == '\0')
break;
tmp = 0;
++i;
}
迅雷笔试编程2题
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n=5;
vector<int> v;
char str[100];
cin >> str;
int i = 0;
int tmp = 0;
//处理逗号隔开的数字
while (str[i] != '\0'){
while (str[i] != '\0' && str[i] != ','){
if (str[i] == 'A')
str[i] = '1';
else if (str[i] == 'J' || str[i] == 'Q' || str[i] == 'K')
str[i] = '0' + 10;
tmp = tmp * 10 + str[i]-'0';
++i;
}
v.push_back(tmp);
if (str[i] == '\0')
break;
tmp = 0;
++i;
}
//
int a[3] = { 0 };
int has = 0;
for (int i = 0; i < 3; ++i){
for (int j = i+1; j < 4; ++j){
for (int k = j+1; k < 5; ++k){
if ((v[i] + v[j] + v[k])>=10&&(v[i] + v[j] + v[k]) % 10 == 0){
a[0] = i;
a[1] = j;
a[2] = k;
++has;
break;
}
}
}
}
if (has == 0)
cout << "none" << endl;
else{
int sum = 0;
for (int i = 0; i < 5; ++i){
if (i != a[0] && i != a[1] && i != a[2]){
sum += v[i];
}
}
if (sum >= 10 && sum % 10 == 0){
cout << "10" << endl;
}
else{
cout << sum % 10 << endl;
}
}
system("pause");
return 0;
}
转载于:https://blog.51cto.com/lingdandan/1854231