http://codeforces.com/gym/101190/attachments
恶心的模拟题,队友写的代码。
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string inn,out,wrd,cu1,cu2;
int co1,co2;
bool jup(char c)
{
if('A'<=c&&c<='Z') return 1;
else return 0;
}
bool jdw(char c)
{
if('a'<=c&&c<='z') return 1;
else return 0;
}
void cln()
{
cu1=cu2="";
co1=co2=0;
}
int main()
{
freopen("abbreviation.in","r",stdin);
freopen("abbreviation.out","w",stdout);
while(getline(cin,inn))
{
out=""; cln();
for(int i=0;i<inn.size();i++)
{
int j;
int fup=0,icd=0;
for(j=i;j<inn.size();j++)
{
if(jup(inn[j])||jdw(inn[j]));
else break;
wrd+=inn[j];
if(j==i&&jup(inn[j])) fup=1;
if(j!=i&&jup(inn[j])) fup=0;
if(jdw(inn[j])) icd=1;
}
if(fup&&icd)
{
if(co1&&co2==0) co2=1;
if(co1==0) co1=1;
cu1+=inn[i],cu2+=wrd+inn[j];
}
else
{
if(co2==0) out+=cu2,cln();
if(co2==1) out+=cu1 + " ("+cu2.substr(0,cu2.size()-1)+")" + cu2[cu2.size()-1],cln();
out+=wrd;
if(j!=inn.size()) out+=inn[j];
}
if(inn[j]!=' '&&j!=inn.size())
{
if(co2==0) out+=cu2,cln();
if(co2==1) out+=cu1 + " ("+cu2.substr(0,cu2.size()-1)+")" + cu2[cu2.size()-1],cln();
}
i=j;
wrd="";
}
if(inn[inn.size()-1]==' ')
{
if(co2==0) out+=cu2,cln();
if(co2==1) out+=cu1 + " ("+cu2.substr(0,cu2.size()-1)+")" + cu2[cu2.size()-1],cln();
}
else
{
if(co2==0) out+=cu2.substr(0,cu2.size()-1),cln();
if(co2==1) out+=cu1 + " (" + cu2.substr(0,cu2.size()-1) + ")" ,cln();
}
//cout<<out.size()<<endl;
cout<<out<<endl;
}
return 0;
}