UVA Live 7770
真的是恶心到我了,怎么会有这么恶心的模拟题目呢,写了好几遍,一晚上就荒废了
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <math.h>
#include <ctype.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-9;
vector<string> cans;
string str;
string s;
bool judge(string &s)
{
int n = s.size();
if(n <= 1) return false;
if(!isupper(s[0])) return false;
for(int i = 1; i < n; i++)
{
if(!islower(s[i])) return false;
}
return true;
}
int main()
{
while(getline(cin, str))
{
str += '.';
int n = str.size();
s = "";
for(int i = 0; i < n; i++)
{
if(isalpha(str[i]))
{
s += str[i];
}
else if(str[i] == ' ')
{
if(judge(s))
{
cans.push_back(s);
s = "";
}
else
{
if(cans.size() >= 2)
{
string tmp = "";
for(int j = 0; j < cans.size(); j++)
tmp += cans[j][0];
tmp += " (";
for(int j = 0; j < cans.size(); j++)
{
if(j) tmp += " ";
tmp += cans[j];
}
tmp += ")";
cout<<tmp;
}
else
{
string tmp = "";
for(int j = 0; j < cans.size(); j++)
{
if(j) tmp += " ";
tmp += cans[j];
}
cout<<tmp;
}
string tmp = "";
if(cans.size() >= 1) tmp += " ";
tmp += s;
tmp += " ";
s ="";
cout<<tmp;
cans.clear();
}
}
else if(str[i] != ' ')
{
if(judge(s))
{
cans.push_back(s);
}
if(cans.size() >= 2)
{
string tmp = "";
for(int j = 0; j < cans.size(); j++)
tmp += cans[j][0];
tmp += " (";
for(int j = 0; j < cans.size(); j++)
{
if(j) tmp += " ";
tmp += cans[j];
}
tmp += ")";
cout<<tmp;
}
else
{
string tmp = "";
for(int j = 0; j < cans.size(); j++)
{
if(j) tmp += " ";
tmp += cans[j];
}
cout<<tmp;
}
string tmp = "";
if(judge(s))
tmp += str[i];
else
{
if(cans.size() >= 1)
tmp += " ";
tmp += s;
tmp += str[i];
}
if(i == n-1) tmp.resize(tmp.size()-1);
cout<<tmp;
s="";
cans.clear();
}
}
cout<<endl;
}
return 0;
}
所以说没有啥大事是重写一遍解决不了的,如果有,那就再写一遍