写PTA

`#define _CRT_SECURE_NO_WARNINGS

include

include

include

using namespace std;
void show(const string& a)//输出函数
{
for (int i = 0; i < a.size(); i++)
{
cout << a[i];
if (i != a.size() - 1)
{
cout << ",";
}
}
}
int main()
{
string id;
string arr;
string index;
cin >> id;
for (char c : id)//统计号码中出现的数字
{
if (arr.find(c) == string::npos)
{
arr += c;
}
}
sort(arr.begin(), arr.end(), greater());//排序
for (char c : id)//查找并且统计索引
{
index += to_string(arr.find(c));
}
//输出arr数组
cout << "int[] arr = new int[]{";
show(arr);
cout << "};" << endl;
//输出index索引
cout << "int[] index = new int[]{";
show(index);
cout << "};" << endl;
return 0;
} #define _CRT_SECURE_NO_WARNINGS

include

include

include

using namespace std;
bool func(string& a , int& n)//判断是否全为数字并给输入的数字赋值
{
for (char c : a)//数字判断
{
if (!isdigit(c))
{
return false;
}
}
stringstream ss(a);
if (!(ss >> n))
{
return false;
}
if (n > 1000 || n < 1)//转换后大小判断
{
return false;
}
return true;
}
int main()
{
string line;
getline(cin, line);
string A;
string B;
int index = line.find(' ');
A = line.substr(0, index);
B = line.substr(index + 1);
int numA = 0;
int numB = 0;
if (!func(A, numA))
{
A = '?';
}
if (!func(B, numB))
{
B = '?';
}
//输出判断
if (A == "?" && B == "?")
{
cout << A << " + " << B << " = " << "?" << endl;
}
else if (A == "?" && B != "?")
{
cout << A << " + " << numB << " = " << "?" << endl;
}
else if (A != "?" && B == "?")
{
cout << numA << " + " << B << " = " << "?" << endl;
}
else if (A != "?" && B != "?")
{
cout << numA << " + " << numB << " = " << numA + numB << endl;
}
return 0;
} #define _CRT_SECURE_NO_WARNINGS

include

include

include

using namespace std;
int main()
{
string input;
cin >> input;
int countG = 0;
int countP = 0;
int countL = 0;
int countT = 0;
for (char a : input)//全部转大写
{
a = toupper(a);
if (a == 'G')
{
countG++;
}
if (a == 'P')
{
countP++;
}
if (a == 'L')
{
countL++;
}
if (a == 'T')
{
countT++;
}
}
while (countG != 0 || countP != 0 || countL != 0 || countT != 0)
{
if (countG != 0)
{
cout << "G";
countG--;
}
if (countP != 0)
{
cout << "P";
countP--;
}
if (countL != 0)
{
cout << "L";
countL--;
}
if (countT != 0)
{
cout << "T";
countT--;
}
}
cout << endl;
return 0;
}`
明天大概率看看Java

posted @ 2025-07-12 15:46  白底纸板  阅读(8)  评论(0)    收藏  举报