📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
查看: 1629| 回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

求一题解法(difficult)

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 woodman 于 2016-3-6 03:46 编辑

Problem Statement

You are given a list of clues, and all clues have the same length. Some of the letters are missing, and those letters are represented by question marks ('?'). Arrange the clues in a vertical row, such that corresponding characters in each clue are in the same column. Then, order the clues so that each column is sorted in non-decreasing order from top to bottom. You can replace each question mark with any letter to achieve this

Print the new list of clues containing the lexicographically earliest ordering that you can achieve. If there is no way to achieve the goal, print NONE instead. An ordering A comes before an ordering B if A contains an alphabetically earlier clue at the first index where they differ

Input

Line 1: N

Line 2 .. N + 1: clue_i

Output

As stated in the problem statement

Input Explanation

Line 1: N, the number of clues

Line 2 to line N+1: clue_i, uppercase A-Z characters

Output Explanation

Output will contain exactly N lines or NONE if no such ordering is possible

Sample Input

3

?ED?

TO??

????

Sample Output

AAAA

AEDA

TODA
如题  求个java 的解法 求大家指点 多谢了
import java.io.*;
import java.util.*;
class Test {
    public static void main(String [] args) throws Exception{
        BufferedReader in = new BufferedReader(
            new InputStreamReader(System.in));
        String str = in.readLine();
}
}

上一篇:排序好的数组中找第一个重合点
下一篇:求教bfs/dfs
🔗
ccarter 2016-3-8 08:24:01 | 只看该作者
全局:
说一下算法吧,应该是对的,代码不写了
每个string都当做一个结点,如果对于两个string a和b,存在一个index使得a[i] != '?' && b[i] != '?' && a[i] < b[i],就在a b之间连一条有向边,a指向b。所有的string pair都处理完成后对图进行拓扑排序,排序的结果就是string排好的顺序,把所有?替换成合适的字符即可。如果无法拓扑排序就输出NONE。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表