Codeforces Gym 100286I iSharp 水题

Problem I. iSharp
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/I

Description

You are developing a new fashionable language that is not quite unlike C, C++, and Java. Since your language should become an object of art and fashion, you call it i # (spelled i-sharp). This name combines all the modern naming trends and also hints at how smart you are. Your language caters for a wide auditory of programmers and its type system includes arrays (denoted with “[]”), references (denoted with “&”), and pointers (denoted with “*”). Those type constructors can be freely combined in any order, so that a pointer to an array of references of references of integers (denoted with “int&&[]*”) is a valid type. Multiple variables in i # can be declared on a single line with a very convenient syntax where common type of variables is given first, followed by a list of variables, each optionally followed by additional variable-specific type constructors. For example, the following line: int& a*[]&, b, c*; declares variables a, b, and c with types “int&&[]*”, “int&”, and “int&*” correspondingly. Note, that type constructors on the right-hand sides of variables in i # bind to variable and their order is reversed when they are moved to the left-hand side next to type. Thus “int*& a” is equivalent to “int a&*”. However, you discover that coding style with multiple variable declarations per line is confusing and is outlawed in many corporate coding standards. You decide to get rid of it and refactor all existing i # code to a single variable declaration per line and always specify type constructor next to the type it refers to (instead of the right-hand side of variable). Your task it to write such refactoring too

Input

The input file contains a single line with a declaration of multiple variables in i #. The line starts with a type name, followed by zero, one, or more type constructors, followed by a space, followed by one or more variable descriptors separated by “,” (comma) and space, and terminated by “;” (semicolon). Each variable descriptor contains variable name, followed by zero, one, or more type constructors. Type name and variable names are distinct and consist of lowercase and uppercase English letters from “a” to “z” or “A” to “Z”. The line contains at most 120 characters and does not contain any extra spaces.

Output

Write to the output file a line for each variable declared in the input file. For each variable write its declaration on a single line in the same format as in the input file, but with all type constructors next to its type. Separate type with all type constructors from a variable name by a single space. Do not write any extra spaces.

Sample Input

int& a*[]&, b, c*; 

Sample Output

int&&[]* a;
int& b;
int&* c;

HINT

 

题意

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1)

using namespace std;
string str;
string sb;
string temp;
string name;
string sign;
int a1 = 0 , a2 = 0 , a3 = 0;

void GetName()
{
    name.clear();sign.clear();
    for(int i = 0 ; i < temp.size() ; ++ i)
    {
        if ( (temp[i] <= 'Z' && temp[i] >= 'A' ) || (temp[i] <= 'z' && temp[i] >= 'a') )
        {
            name.pb(temp[i]);
        }
        else
        sign.pb(temp[i]);
    }
    reverse(sign.begin(),sign.end());
    for(int i = 0 ; i < sign.size() ; ++ i)
    {
        if (sign[i] == '[') sign[i] = ']';
        else if(sign[i] == ']') sign[i] = '[';
    }
}


int main(int argc,char *argv[])
{
  freopen("isharp.in","r",stdin);
  freopen("isharp.out","w",stdout);
  getline(cin,str);
  int bg;
  for(int i = 0 ; i< str.size() ; ++ i)
  {
       if (str[i] == ' ')
       {
           sb = str.substr(0,i);
           bg = i;
           break;
       }
  }
  int pre = bg;
  for(int i = bg ; i < str.size() ; ++ i)
  {
       if (str[i] == ',' || str[i] == ';')
       {
           temp.clear();
           temp = str.substr(pre+1,i-pre-1);
           GetName();
           cout << sb << sign << " "<< name << ';'<<endl;
           i ++;
           pre = i;
       }
  }
  return 0;
}

 

题,然后倒着输出字符就好了

题解

模拟一下就好了

代码:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值