zoukankan      html  css  js  c++  java
  • Codeforces Round #375 (Div. 2)

    题目链接:http://codeforces.com/contest/723/problem/B

    题意:给定一个字符串。只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词。现在要你输出括号外面的单词的最大长度和括号里面出现的单词数目

    思路:按照题目模拟就好了。写的比较搓。

    #define _CRT_SECURE_NO_DEPRECATE
    #include<stdio.h>  
    #include<string.h>  
    #include<cstring>
    #include<algorithm>  
    #include<queue>  
    #include<math.h>  
    #include<time.h>
    #include<vector>
    #include<iostream>
    using namespace std;
    typedef long long int LL;
    const int INF = 0x3f3f3f3f;
    const int MAXN = 300 + 10;
    int n;
    char str[MAXN];
    int main(){
        while (~scanf("%d", &n)){
            scanf("%s", str);
            bool inner = false; int maxlen = 0, cnt = 0;
            for (int i = 0; i<strlen(str); i++){
                if (str[i] == '_'){
                    continue;
                }
                if (str[i] == '('){
                    int k = i + 1; bool haschar = false;
                    for (; k<strlen(str); k++){
                        if (str[k] == ')'){
                            cnt += (haschar ? 1 : 0);
                            i = k; break;
                        }
                        if (str[k] == '_'){
                            cnt += (haschar ? 1 : 0);
                            haschar = false;
                        }
                        else{
                            haschar = true;
                        }
                    }
                }
                else{
                    int k = i; int tmplen = 0;
                    for (; k <= strlen(str); k++){
                        if (k == strlen(str)){
                            maxlen = max(maxlen, tmplen);
                            i = k;
                            break;
                        }
                        else if (str[k] == '_'){
                            maxlen = max(maxlen, tmplen);
                            tmplen = 0;
                            continue;
                        }
                        else if (str[k] == '('){
                            maxlen = max(maxlen, tmplen);
                            i = k - 1;
                            break;
                        }
                        else{
                            tmplen++;
                        }
                    }
                }
            }
            printf("%d %d
    ", maxlen, cnt);
        }
        return 0;
    }
  • 相关阅读:
    使用jsonp跨域调用百度js实现搜索框智能提示(转)
    jsonp 跨域
    Aixs2发布webservice服务
    java web service 上传下载文件
    java 网页 保存上传文件
    flash、js 函数 互相调用
    java web工程启动socket服务
    mysql 在Windows下自动备份
    Servlet中几个常用方法的推衍
    Tomcat常用设置 <持续更新>
  • 原文地址:https://www.cnblogs.com/kirito520/p/5930067.html
Copyright © 2011-2022 走看看