"尚学堂杯"哈尔滨理工大学第七届程序设计竞赛 F.Final Ugly English(字符串处理)

F.Final Ugly English
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 2074 (405 users)Total Accepted: 294 (291 users)Special Judge: No
Description

ACM twist-toy encountered such a problem in the work, this article, to ensure that this article only lowercase

letters and spaces, please send the articles in each word inverted output, such as "hello world this is an 

competition". You should output "olleh dlrow siht si na noititepmoc".

Input

A group of data, each line of data input from the lower case letters and spaces of the article,

the length of not more than one thousand

Output
Output a line for each word after the reversal of the article.
Sample Input
hello world this is an competition
Sample Output
olleh dlrow siht si na noititepmoc


思路:这里get 到的就是reverse()函数的字符串翻转。但是在我自己打代码的时候发现了一个比较好玩的两边对称翻转,另附代码2上;

注:char 类型的字符串整行输入是gets(a);但是string 类型的整行输入是getline(cin,a);



#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxx 1010
const int mod=10007;
int broken[maxx];
int num[maxx];
int main()
{
  string a;
   while(getline(cin,a))
   {
       int len=a.length();
       for(int i=0;i<len;i++)
       {
           int j;
           int l;
           l=i;
           for(j=l;a[j]!=' '&&j<len;j++);
           i=j;
          reverse(a.begin()+l,a.begin()+j);

       }
       cout<<a<<endl;
   }
    return 0;
}


代码2:


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxx 1010
const int mod=10007;
int broken[maxx];
int num[maxx];
int main()
{
  string a;
   while(getline(cin,a))
   {
       int len=a.length();
       for(int i=0;i<len;i++)
       {
           int j;
           int l;
           l=i;
           for(j=l;a[j]!=' '&&j<len;j++);
           //i=j;
          reverse(a.begin()+l,a.begin()+j);

       }
       cout<<a<<endl;
   }
    return 0;
}


行结果有兴趣的可以自己运行看看。(其实是 我附不上图片委屈




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值