Codeforces - 801

题意:
  
给一个字符串,找出字符串的中 VK 组合。另外,如果有连续的 VV 或者是 KK 组合,可以修改其中一个字符,使其变为VK,但只能修改一次

思路:
  统计出 VK 组合的个数,将 VK 组合的字符串变为‘_' ,然后再判断会不会出现两个连续的字符。有出现 则结果+1 ,否则直接输出结果


代码:
  
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#define Pair pair<int,int>
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0
#define maxn 200001
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;

int main() { string str; cin >> str; int ans = 0; int cnt = 0; for(int i = 0;i < str.length();i++){ if(str[i] == 'V'&& str[i+1]=='K'){ str[i] = '_';str[i+1] = '_'; ans++;i++; } } for(int i = 0;i < str.length();i++){ if(str[i] == str[i+1] && str[i]!='_')cnt++; } if(cnt==0)printf("%d\n",ans); else printf("%d\n",ans+1); return 0; }

 


  
http://codeforces.com/contest/801/problem/B
题意:
   字符串 s1 和 s2 ,长度相同,将这连个字符串的相同下标的ASCLL码小的字符取出放到 s3 中
   现在已知 s1 和 s3 ,求 s2 的是什么字符并输出
  
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#define Pair pair<int,int>
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0
#define maxn 200001
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;

int main()
{
    string str1;
    string str2;
    char str[100] = " ";
    cin >> str1 >> str2;
    for(int i = 0;i < str1.length();i++){
        if(str1[i] > str2[i])str[i] = str2[i];
        if(str1[i] == str2[i]) str[i] = str1[i]+1;
        if(str2[i] == str1[i] && str1[i] == 'z')str[i] = str1[i];
        if(str1[i] < str2[i]){cout << -1 << endl; return 0;}
    }
    for(int i = 0;i < str1.length();i++)cout << str[i];
    cout << endl;
    return 0;
}


/*
aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf
aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf
挂掉的数据   需要对 z 进行特判

*/

 

  



posted @ 2017-04-20 11:37  渣渣技术狗  阅读(73)  评论(0)    收藏  举报