zoukankan      html  css  js  c++  java
  • hiho一下第107周《Give My Text Back》

    题目链接:传送门

    题目大意:给你多组格式不标准的字符串句子,要你恢复到标准格式(单词中间只有一个空格或者一个逗号一个空格,句子的首字母大写其他小写,遇到回车也要换行)

    题目思路:直接按题意模拟,注意几个标记变量的状态改变就行

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <cstring>
    #include <stack>
    #include <cctype>
    #include <queue>
    #include <string>
    #include <vector>
    #include<functional>
    #include <set>
    #include <map>
    #include <climits>
    #define lson root<<1,l,mid
    #define rson root<<1|1,mid+1,r
    #define fi first
    #define se second
    #define ping(x,y) ((x-y)*(x-y))
    #define mst(x,y) memset(x,y,sizeof(x))
    #define mcp(x,y) memcpy(x,y,sizeof(y))
    using namespace std;
    #define gamma 0.5772156649015328606065120
    #define MOD 1000000007
    #define inf 0x3f3f3f3f
    #define N 30005
    #define maxn 100005
    typedef pair<int,int> PII;
    typedef long long LL;
    
    char ch;
    string st="";
    
    int main(){
        int i,j,x,y;
        int dax=1,kong=0;
        while(cin>>noskipws>>ch){
            if(isalpha(ch)){
                ch=tolower(ch);
                if(dax){
                    if(kong)st+=" ";
                    st+=toupper(ch);
                    dax=0;
                }
                else{
                    st+=ch;
                }
                kong=1;
            }
            else{
                if(ch==','){
                    if(st[st.length()-1]==' ')st[st.length()-1]=',';
                    else st+=',';
                    st+=" ";
                    kong=0;
                }
                else if(ch=='.'){
                    if(st[st.length()-1]==' ')st[st.length()-1]='.';
                    else st+='.';
                    kong=1;
                    dax=1;
                }
                else if(ch==' '||ch=='	'){
                    if(kong){
                        st+=" ";
                        kong=0;
                    }
                }
                else if(ch=='
    '){
                    if(st!=""){
                        int len=st.length();
                        for(i=len-1;i>=0;--i)if(st[i]!=' ')break;
                        st=st.substr(0,i+1);
                        cout<<st<<endl;
                        dax=1;kong=0;
                        st="";
                    }
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    [Effective C++ --012]复制对象时勿忘其每一个成分
    [016]转--C++拷贝构造函数详解
    Oracle给用户权限
    Oracle清屏方法
    Oracle 创建数据库、表用户及权限设置代码
    第三人称角色移动及自由移动视野(RigidBody实现)
    unity3D延迟函数
    第一人称角色移动及自由移动视野(CharacterController实现)
    u3d场景载入
    u3D自动寻路2
  • 原文地址:https://www.cnblogs.com/Kurokey/p/5678720.html
Copyright © 2011-2022 走看看