• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 518A Vitaly and Strings (水题,字符串)

题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间。

析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <cmath>
#include <map>
#include <cctype>

using namespace std;
const int maxn = 1000 + 5;
string s, t;

int main(){
    while(cin >> s >> t){
        int n = s.size();
        int cnt = 0;
        ++s[n-1];
        if(s[n-1] > 'z'){ s[n-1] = 'a';  cnt = 1; }
        for(int i = n-2; i >= 0; --i){
            s[i] += cnt;
            if(s[i] > 'z'){ s[i] = 'a';  cnt = 1; }
            else  cnt = 0;
        }
        if(s == t)  puts("No such string");
        else  cout << s << endl;

    }
    return 0;
}

 

posted on 2016-07-07 00:22  dwtfukgv  阅读(285)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3