一道简单C++题目

来源:百度知道 编辑:UC知道 时间:2024/04/28 04:30:03
#include"iostream"
using namespace std;
int main(){
int n;
while(scanf("%d",&n)==1){
char s[10],t[10];
cin>>s>>t;
for(int i=0,j=n-1;i<n&&j>=0;i++,j--)
if(s[i]!=t[j])
break;
if(i!=n){
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
}
else{
cout<<"Yes."<<endl;
for(int k=0;k<n;k++)
cout<<"in"<<endl;
for(int m=0;m<n;m++)
cout<<"out"<<endl;
cout<<"FINISH"<<endl;
}
}
return 0;
}

http://acm.hdu.edu.cn/showproblem.php?pid=1022
这为我做题目的网址。我在想。
为什么我的通不过去捏。
难道只有用栈 才能通过

用scanf得加#include<stdio.h>吧。
你这是要判断字符串是不是另一个字符串的反序?
这个根本就不需要用栈,数组够了。
我觉得你通不过是cin的写法有问题。这种情况下,你应该用循环读字符到数组中。或者,你把char数组用string实现。
最后的两个for语句没什么用。

恩 只能 用栈

吧你的代码整理一下

当遇到等于的就直接return了 别break;

然后继续执行下面的 这样在大量的数据前能省点时间

然后还不行就用栈吧

用 栈

那些Oj很挑剔的
多改一下应该就没问题了

用栈吧,挺方便的
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
string s,t;
cin>>s>>t;
stack<int>S;
int i=0,j=0;
int cnt=0;
string g[100];
while(i<=n&&j<n)
{
if(S.empty()==true || S.top()!=t[j])
{
g[cnt++]="in";
S.push(s[i]);
i