POJ 2743 字符串判等 解题报告

POJ 2743 字符串判等 解题报告

编号:2743

 

考查点:字符串操作

 

思路: 把第一个字符串变成标准格式,然后拿第二个与之比较

 

提交情况: 因为比较的时候未考虑第一个字符串有效字符比第二个多的情况,WA了几次,后来只循环条件加了个等号就AC了

 

Source Code

 

//POJ Grids 2743
#include <iostream>
using namespace std;

char s1[110];
char s2[110];
char temp[110];

void Get()
{
    cin.getline(s1,
110);
    cin.getline(s1,
110);
    cin.getline(s2,
110);
}

int main()
{
    
int n;scanf("%d",&n);
    
while (n--)
    {
        memset(temp,
0,sizeof temp);
        memset(s1,
0,sizeof s1);
        memset(s2,
0,sizeof s2);
        Get();

        
int len = strlen(s1);
        
int k = 0;
        
for (int i=0;i<len;i++)
        {
            
if (s1[i]!=' ')
            {
                
if (s1[i]>='a'&&s1[i]<='z')
                    s1[i] 
-= 32;
                temp[k
++= s1[i];
            }
        }
        len 
= strlen(s2);
        
bool flag = false;
        k 
= 0;
        
for (int i=0;i<=len;i++)
        {
            
if (s2[i]!=' ')
            {
                
if (s2[i]>='a'&&s2[i]<='z')
                    s2[i] 
-= 32;
                
if (s2[i]!=temp[k++])
                {
                    flag 
= true;
                    
break;
                }
            }
        }
        
if (!flag)
            cout
<<"YES"<<endl;
        
else
            cout
<<"NO"<<endl;
    }
    
return 0;
}

 

总结: 复出第二题,这个让我浪费了很长时间的题..

 

                                                       By   Ns517

                                                      Time 09.03.21

posted @ 2009-03-21 01:11  端木  阅读(1189)  评论(0编辑  收藏  举报