MENU

找字符串

September 12, 2020 • Read: 26 • 默认分类

请输入图片描述

/*
 * @Author       : 剑枫
 * @Date         : 2020-09-07 00:07:28
 * @LastEditors  : 剑枫
 * @LastEditTime : 2020-09-09 19:38:18
 * @FilePath     : \visual c++基本算法\chengfa.cpp
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T>
int ppp(char *s)
{
    if (s == NULL)
        return 0;
    int cnt = 0;
    for (int i = 0; i < strlen(s); i++)
    {
        if (*(s + i) == '*')
            cnt++;
    }
    return cnt;
}
char *findans(char **s, int n)
{
    char *ans = NULL;
    for (int i = 0; i < n; i++)
    {
        if (ppp(ans) < ppp(*(s + i)))
        {
            ans = *(s + i);
        }
    }
    return ans;
}
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    char **s;
    int n;
    while(~scanf("%d", &n))
    {
        s = (char **)calloc(sizeof(char *), n);
        for (int i = 0; i < n; i++)
        {
            *(s + i) = (char *)calloc(sizeof(char), 1005);
            scanf("%s", *(s + i));
        }
        printf("%s\n", findans(s, n));
    }
    return 0;
}
Last Modified: September 18, 2020