在vs2017可以正常运行,但是赛码上不行,发现赛码没有size这个函数,无语了。
#include<iostream>
#include<string>
#include <ctype.h>
using namespace std;
int main()
{
int T;
cin >> T;
string*s = new string[T];
for (int i = 0; i < T; i++)
{
cin >> s[i];
}
for (int i = 0; i < T; i++)
{
int a = 0;
int n1 = 0, n2 = 0, b = -1, c = 0, d = 0, s1 = 0;
int len = 0;
len = size(s[i]);
cout << "长度"<<len << endl;
for (int j = 0; j < len; j++)
{
//判断大写字母的个数,以及位置
if (s[i][j] >= 'A'&&s[i][j] <= 'Z')
{
n1++;
if (b + 1 != j )
{
c = c + 2;//大写字母不相邻的个数
}
b = j;//b用来保存大写字母的位置
//cout << j <<" ";
if (s[i][0] >= 'A'&&s[i][0] <= 'Z')
{
a = 1;//首字母为大写
}
}
//计算小写字母的个数
else if (s[i][j] >= 'a'&&s[i][j] <= 'z')
{
n2++;
if (s[i][len-1] >= 'a'&&s[i][len-1] <= 'z')
{
d = 1;//尾字母为小写
}
if (s[i][0] >= 'a'&&s[i][0] <= 'z')
{
s1 = 1;//首字母为小写
}
}
}
if (n2==0)//全为大写字母
{
a = 1;
c = d = s1 = 0;
}
if (n1 == 0)//全为小写字母
{
a = 0;
c = d = s1 = 0;
}
if (n1 == 1 && s1== 1)
{
c = 0;//只有一个大写字母且首字母为小写
}
cout << n1 + n2 << " " << a << " " << c << " " << d << " " << s1<<endl;
cout << n1 + n2 + a + c + d+s1 << endl;
//cout << n1 << " " << n2 << endl;
//cout << n1 + n2 +c<< endl;
}
}