zoukankan      html  css  js  c++  java
  • UVA Live 7770 模拟

    UVA Live 7770

    题目链接

    真的是恶心到我了,怎么会有这么恶心的模拟题目呢,写了好几遍,一晚上就荒废了

    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <vector>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <string>
    #include <math.h>
    #include <ctype.h>
    using namespace std;
    typedef pair<int,int> P;
    typedef long long LL;
    const int INF = 0x3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-9;
    vector<string> cans;
    string str;
    string s;
    
    bool judge(string &s)
    {
        int n = s.size();
        if(n <= 1) return false;
        if(!isupper(s[0])) return false;
        for(int i = 1; i < n; i++)
        {
            if(!islower(s[i])) return false;
        }
        return true;
    }
    
    int main()
    {
        while(getline(cin, str))
        {
            str += '.';
            int n = str.size();
            s = "";
            for(int i = 0; i < n; i++)
            {
                if(isalpha(str[i]))
                {
                   s += str[i];
                }
                else if(str[i] == ' ')
                {
                    if(judge(s))
                    {
                        cans.push_back(s);
                        s = "";
                    }
                    else
                    {
                        if(cans.size() >= 2)
                        {
                            string tmp = "";
                            for(int j = 0; j < cans.size(); j++)
                                tmp += cans[j][0];
                            tmp += " (";
                            for(int j = 0; j < cans.size(); j++)
                            {
                                if(j) tmp += " ";
                                tmp += cans[j];
                            }
                            tmp += ")";
                            cout<<tmp;
                        }
                        else
                        {
                            string tmp = "";
                            for(int j = 0; j < cans.size(); j++)
                            {
                                if(j) tmp += " ";
                                tmp += cans[j];
                            }
                            cout<<tmp;
                        }
                        string tmp = "";
                        if(cans.size() >= 1) tmp += " ";
                        tmp += s;
                        tmp += " ";
                        s ="";
                        cout<<tmp;
                        cans.clear();
                    }
                }
                else if(str[i] != ' ')
                {
                    if(judge(s))
                    {
                        cans.push_back(s);
                    }
                    if(cans.size() >= 2)
                    {
                        string tmp = "";
                        for(int j = 0; j < cans.size(); j++)
                            tmp += cans[j][0];
                        tmp += " (";
                        for(int j = 0; j < cans.size(); j++)
                        {
                            if(j) tmp += " ";
                            tmp += cans[j];
                        }
                        tmp += ")";
                        cout<<tmp;
                    }
                    else
                    {
                        string tmp = "";
                        for(int j = 0; j < cans.size(); j++)
                        {
                            if(j) tmp += " ";
                            tmp += cans[j];
                        }
                        cout<<tmp;
                    }
                    string tmp = "";
                    if(judge(s))
                        tmp += str[i];
                    else
                    {
                        if(cans.size() >= 1)
                            tmp += " ";
                        tmp += s;
                        tmp += str[i];
                    }
                    if(i == n-1) tmp.resize(tmp.size()-1);
                    cout<<tmp;
                    s="";
                    cans.clear();
                }
            }
            cout<<endl;
        }
        return 0;
    }
    

    所以说没有啥大事是重写一遍解决不了的,如果有,那就再写一遍

    如果有错误,请指出,谢谢
  • 相关阅读:
    Uva 11806 拉拉队 二进制+容斥原理 经典!
    CSU CHESS
    hdu 4049 Tourism Planning 状态压缩dp
    HDOJ 4661: Message Passing(找递推公式+逆元)
    HDU
    hdu4647(思路啊!)
    spoj 370. Ones and zeros(搜索+同余剪枝+链表存数(可能越界LL))
    URAL
    URAL
    hdu4614 (二分线段树)
  • 原文地址:https://www.cnblogs.com/Alruddy/p/7368478.html
Copyright © 2011-2022 走看看