7 solutions
-
0
#include<bits/stdc++.h> using namespace std; const int N=10010; bool f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
-
-1
#include<bits/stdc++.h> using namespace std; const int N=10010; bool f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
-
-1
#include<bits/stdc++.h> using namespace std; const int N=10010; bool f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
-
-1
#include<bits/stdc++.h> using namespace std; const int N=10010; bool f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
-
-1
#include<bits/stdc++.h> using namespace std; const int N=10010; bool f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
-
-1
#include<bits/stdc++.h> using namespace std; const int N=10010; bool f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
-
-2
#include<bits/stdc++.h> using namespace std; const int N=1010; int f[N][N]; //f[i][j]=1 表示i到j这段是回文串 int main() { string s; cin>>s; int n=s.size(); s=" "+s; for(int i=1;i<=n;i++) f[i][i]=1; //一个字符一定是回文 int ans=n; for(int i=n;i>=1;i--) { for(int j=i+1;j<=n;j++) { if(s[i]!=s[j]) continue;//一定不符合要求 if(j==i+1||f[i+1][j-1]) { ans++; f[i][j]=true; } } } cout<<ans; return 0; }
- 1
Information
- ID
- 208
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 44
- Accepted
- 10
- Uploaded By