zoukankan      html  css  js  c++  java
  • 【习题 8-2 UVA-1610】Party Games

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    字符串排序后 显然是n/2-1和n/2这两个字符串进行比较。 设为a,b 找到第一个不相同的位置。 即0..i-1是相同的前缀,然后第i位不一样了。 则如果i是a的最后一位了。 那么直接输出a就好。 这样满足大于等于a且小于b

    否则
    如果b[i]-a[i]>1 则可以直接把这一位a[i]加1以及前面的前缀然后输出
    或者i不是b的最后一位那么也可以这样直接加1输出。
    这样输出的s就是b的一个前缀了。肯定小于b,又大于a.

    如果b[i]-a[i]==1且i是b的最后一位。
    那么就不能直接输出+1后的结果了。
    那样的话输出的s就和b一样了。
    那么我们保留a[i]然后在后面的某一个位置找个机会(某个字符)+1;
    或者直接就是整个字符串b了

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    int n;
    vector <string> v;
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        while (cin >> n && n){
            v.clear();
            for (int i = 1;i <= n;i++){
                string x;
                cin >> x;
                v.push_back(x);
            }
            sort(v.begin(),v.end());
            int mid = n/2;
            string s1 = v[mid-1],s2 = v[mid];
            string temp = "";
            for (int i = 0;i < (int)s1.size() && i<(int)s2.size();i++)
                if (s1[i]==s2[i]){
                    temp+=s1[i];
                }else{
                    if (i==(int)s1.size()-1){
                        temp+=s1[i];
                    }else if (s2[i]-s1[i]>1 || i!=(int)s2.size()-1){
                                temp+=(s1[i]+1);
                            }else{
                                temp+=s1[i];
                                for(int j = i+1;j < (int)s1.size();j++){
                                    if (j==(int)s1.size()-1){
                                        temp+=s1[j];break;
                                    }
                                    if (s1[j]!='Z'){
                                        temp+=(s1[j]+1);break;
                                    }
                                    temp+='Z';
                                }
                            }
                    break;
                }
                cout << temp << endl;
        }
    	return 0;
    }
    
    
  • 相关阅读:
    Get distinct count of rows in the DataSet
    单引号双引号的html转义符
    PETS Public English Test System
    Code 39 basics (39条形码原理)
    Index was outside the bounds of the array ,LocalReport.Render
    Thread was being aborted Errors
    Reportviewer Error: ASP.NET session has expired
    ReportDataSource 值不在预期的范围内
    .NET/FCL 2.0在Serialization方面的增强
    Perl像C一样强大,像awk、sed等脚本描述语言一样方便。
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8204814.html
Copyright © 2011-2022 走看看