词组缩写

#include<iostream>
#include<sstream>
#include<queue>
using namespace std;
int main()
{
	const int max = 1000000;
	char str[max];
	char num[max / 10];
	stringstream ss;
	int n, i, j;
	string ans = "";
	queue<string>q;
	cin.getline(num, 10);
	ss << num;
	ss >> n;
	for (i = 0; i <n; i++)
	{
		cin.getline(str, max);
		for (j = 0; j < 100; j++)
		{
			if (j == 0)
			{
				if (str[j] >= 'a' && str[j] <= 'z')
				{
					str[j] -= 'a' - 'A';
					ans += str[j];

				}

				else if (str[j] >= 'A' && str[j] <= 'Z')
				{
					ans += str[j];
				}
			}
			if (str[j] == ' ')
			{
				while (str[j] == ' ')
				{
					j++;
				}
				if (str[j] >= 'a' && str[j] <= 'z')
				{
					str[j] -= 'a' - 'A';
					ans += str[j];

				}

				else if (str[j] >= 'A' && str[j] <= 'Z')
				{
					ans += str[j];
				}

			}

		}
		q.push(ans);
		ans = "";
	}
	while (!q.empty())
	{
		cout << q.front()<< endl;
		q.pop();
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/zhanghua-322/p/11302430.html