心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
细心再细心!宁愿代码长一点,不能在不该出错的地方出错!
以下是我的代码:
#include<iostream>
#include
<string>
using namespace std;
bool yuanyin(char ch)
{
    
const string r("AEIOUaeiou");
    
for(long i=0;i<10;i++)
        
if(ch==r[i])
            
return true;
    
return false;
}
int main()
{
    
string s,one,two,three;
    
long len,num,n;
    
bool found;
    
    getline(cin,s);
    
//  Input
    
    one.clear();
    two.clear();
    three.clear();
    
//  Clear
    
    len
=s.length();
    num
=0;
    
for(long i=0;i<len;i++)
        
if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z'))
        {
            one
+='.';
            num
++;
        }
        
else one+=s[i];
    
if(num%3==0||num%3==1)
        n
=num/3;
    
else n=num/3+1;
    
//  First line
    
    two
=one;
    
for(long i=0,j=0;i<len&&j<n;i++)
        
if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z'))
        {
            two[i]
=s[i];
            j
++;
        }
    
//  Second line
    
    three
=two;
    found
=false;
    
for(long i=0,j=0;i<len;i++)
    {
        
if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z'))
            j
++;
        
if(j==n) i++;
        
if(j>=n&&yuanyin(s[i]))
        {
            three[i]
=s[i];
            found
=true;
        }
    }
    
if(!found)
    {
        
if(2*num%3==0||2*num%3==1)
            n
=2*num/3;
        
else n=2*num/3+1;
        
for(long i=0,j=0;i<len&&j<n;i++)
            
if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z'))
            {
                three[i]
=s[i];
                j
++;
            }
    }
    
//  Third line
    
    cout
<<one<<endl<<two<<endl<<three<<endl;
return 0;
}
posted on 2010-10-11 22:24 lee1r 阅读(116) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:字符串处理

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理