o.boj 1503 Sapphire的反转文

注:最近这一系列ACM的内容,都是2年多之前的代码,自己回顾一下。
 
 
Sapphire的反转文
 
Submit: 824    Accepted:306
Time Limit: 2000MS  Memory Limit: 65535K
Description
每年夏天,ACM集训队都会进行长期的集中训练,一天到晚在机房看点脑,实在太无聊。所以这天yicou想出了一种新的语言:反转文! 反转文词法将一切文字分为3类:单词,非单词,‘#’号 所有以字母开头的词都是单词(无论后面紧跟什么字符,一直到‘#’结束),非字母开头的都是非单词,而‘#’就还是‘#’。一段普通文章的反转文如下: 原文章:abcd##edf.!#+- 反转文:-+#edf.!##abcd 也就是在保持单词的字符序不变的同时,其他全反向(单词、非单词的排列顺序和中间‘#’全反向,非单词内部字符序也反向) 注意:最后一个如果是单词或非单词,没有’#’。 

Input
单组测试数据 只有一行,一个字符串 暨原文章(长度小于1200)。字符串中不包含空格 

Output
输出该文章的反转文 

Sample Input

Question:#In#the#1600's#when#the#Spanish#moved#into#what 


Sample Output

what#into#moved#Spanish#the#when#s'0061#the#In#Question: 


Source
yicou


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main()
{
   string str;
   int end, front, temp;
   int len;
       
   cin >> str;
   len = str.length();
      
   end = temp = len-1;
   
   front = end - 1;
   while (front >= 0)
   {      
      if (str[end] == '#')
      {
         printf("#");
         end--;
         temp = end;
         front = end - 1;
      }
      else
      {
         if (str[front] != '#')
         {
            temp = front;
            front --;
         }
         else
         {
            if (('a'<=str[temp]&&str[temp]<='z') ||
                ('A'<=str[temp]&&str[temp]<='Z'))
               for (int i = temp; i <= end; i++)
                  printf("%c", str[i]);
            else
               for (int i = end; i >= temp; i--)
                  printf("%c", str[i]);
            end = temp - 1;
            temp = end;
            front--;            
         }
      }      
   }
   if (('a'<=str[temp]&&str[temp]<='z') ||
       ('A'<=str[temp]&&str[temp]<='Z'))
      for (int i = temp; i <= end; i++)
         printf("%c", str[i]);
      else
         for (int i = end; i >= temp; i--)
            printf("%c", str[i]);
   cout << endl;
   // system("pause");
   return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值