分析:不是难题,只是折磨人的题,还好要变通变通,运用STL容易解决。
Code
#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
using namespace std;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
deque<string> word;
deque<int> number;
deque<int> offset;
int sum;
void ToLow(const string &s,char c[])
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int len = s.length();
for(int i=0;i<len;++i)
if(s[i]>='A' && s[i]<='Z')
c[i] = s[i] + 32;
else
c[i] = s[i];
c[len] = '\0';
}
bool lessString(const string &l,const string &r)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
char l1[100],r1[100];
ToLow(l,l1);
ToLow(r,r1);
return strcmp(l1,r1)<0;
}
bool IsNumber(char str[])
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int len = strlen(str);
if(str[len-1]>='0' && str[len-1]<='9')
return true;
else
return false;
}
bool Input()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
char str[100];
int myoffset = 0;
bool exit=false;
word.clear();
number.clear();
offset.clear();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while(!exit)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cin>>str;
if(str[0]=='.')
return false;
if(str[strlen(str)-1]=='.')
exit = true;
str[strlen(str)-1] = '\0';
if(IsNumber(str))
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
number.push_back(atoi(str));
offset.push_back(myoffset);
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string s = str;
word.push_back(s);
}
++myoffset;
}
sum = myoffset;
return true;
}
void Display()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
for(int i=0;i<sum;++i)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(!offset.empty() &&offset.front()==i)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cout<<number.front();
number.pop_front();
offset.pop_front();
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cout<<word.front();
word.pop_front();
}
if(i!=sum-1)
cout<<", ";
else
cout<<"."<<endl;
}
}
int main()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
while(Input())
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sort(word.begin(),word.end(),lessString);
sort(number.begin(),number.end());
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Display();
}
return 0;
}