IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> C. Pattern【1200】 -> 正文阅读

[C++知识库]C. Pattern【1200】

Problem - 412C - Codeforces

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.

In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string?aba?matches patterns:????,???a,?a?a,?aba.

Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given?n?patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?

Input

The first line contains a single integer?n?(1?≤?n?≤?105)?— the number of patterns. Next?n?lines contain the patterns.

It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed?105?characters.

Output

In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.

Examples

input

Copy

2
?ab
??b

output

Copy

xab

input

Copy

2
a
b

output

Copy

?

input

Copy

1
?a?b

output

Copy

cacb

Note

Consider the first example. Pattern?xab?intersects with each of the given patterns. Pattern?????also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly,?xab?is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example:?aab,?bab,?cab,?dab?and so on.

题意翻译

给你nn个长度相等的字符串,由小写字母和问号(问号视为任意一个小写字母)组成。你需要输出一个与之长度相等的字符串,使得当这个字符串的第ii位为某个字母时,nn个字符串的第ii位均为这个字母。

如果某一位不符合规定,你需要输出?,(当然如果某一位符合规定也可以输出?)但是问号数目要尽量小。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<string.h>
using namespace std;
// ctrl+shift+C 注释
//ctrl+shift+x 取消
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef pair<int,int> PII;
const int N=2e5+10;
const ll M=1e18+10;
const int mod=1e9+7;
int a[N],sum[N];
priority_queue<int,vector<int>,greater<int> >pq;
set<int>se;
map<int,int>mp;
queue<int>qu;
vector<int>v;
deque<int>de;
string s,ss;
void solve()
{
    int n;
  cin>>n;
  int flag=0;
  for(int i=0;i<n;i++)
  {
      cin>>s;
      if(i==0)
      {
          ss=s;
          continue;
      }
      for(int i=0;s[i];i++)
      {
          if(ss[i]=='?'&&s[i]=='?')
          {
              ss[i]==s[i];
          }
          else if(ss[i]!='?'&&s[i]=='?')
          {
              ss[i]==ss[i];
          }
          else if(s[i]!='?'&&ss[i]!='?')
          {
              if(s[i]!=ss[i]&&ss[i]!='^')
              {
                  ss[i]='^';//都不相同
                  flag++;
              }
          }
          else if(s[i]!='?'&&ss[i]=='?')
          {
              ss[i]=s[i];
          }

      }
  }
  if(!flag)
  {
      for(int i=0;ss[i];i++)
     {
      if(ss[i]=='?')
      {
          ss[i]='z';
      }
     }
    cout<<ss<<endl;
  }
  else
  {
          for(int i=0;ss[i];i++)
          {
              if(ss[i]=='?')
              {
                  ss[i]='z';
              }
              if(ss[i]=='^')
                ss[i]='?';
          }
          cout<<ss<<endl;
  }
}
signed main()
{
   int t=1;
   //cin>>t;
   while(t--)
   {
       solve();
   }
}

emmm。写得略微粗糙了。

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-10-08 20:22:12  更:2022-10-08 20:25:45 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 5:21:28-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码