codeforce 很有意思的一道字符串比较的题

来源:互联网 发布:购买易特软件 编辑:程序博客网 时间:2024/06/08 17:44

这道题考察的是字符串比较的问题,也就是我们平常所说的字符串比较的题,不过数据量很大,而且字符串有大量的重复,我只写了一个基本的算法,可惜超时了,因为有大量已经算出来的数据,不需要在计算,正在找好的算法。。。。。

点击打开链接

#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#include<vector>#include<cstring>using namespace std;char a[1010];char b[1010];int is_win(char a, char b){    switch(a)    {     case 'R': if(b=='R') return 0; else if(b=='P') return -1; else if(b=='S') return 1; break;     case 'P': if(b=='R') return 1; else if(b=='P') return 0; else if(b=='S') return -1; break;     case 'S': if(b=='S') return 0; else if(b=='P') return 1; else if(b=='R') return -1; break;    }}void compare(char *a,char *b, int num){     int m = strlen(a);     int n = strlen(b);     int red1, red2;     red1 = red2 =0;     for(int i=0; i<num; i++)     {      if(is_win(a[i%m],b[i%n])==1)      red2 ++;      else if(is_win(a[i%m],b[i%n])==-1)       red1 ++;     } printf("%d %d\n",red1, red2);}int main(){ int num; scanf("%d",&num); memset(a,'\0',sizeof(a)); memset(b,'\0',sizeof(b)); getchar(); gets(a); gets(b); compare(a,b,num);   //system("pause");   return 0;}