zoukankan      html  css  js  c++  java
  • UVa 353

    称号:字符串统计回文子的数量。

    分析:dp,暴力。因为数据是小,直接暴力可以解决。

    说明:(UVa最终评出800该)。

    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    char str[82];
    char ans[3200][82];
    
    int main()
    {
    	while (~scanf("%s",str)) {
    		int count = 0,len = strlen(str);
    		for (int i = 1 ; i <= len ; ++ i)
    		for (int s = 0 ; s < len ; ++ s) {
    			int flag = 1;
    			for (int t = s+i-1 ; t >= s ; -- t)
    				if (str[s+s+i-1-t] != str[t]) {
    					flag = 0;
    					break;
    				}
    			if (flag) {
    				for (int j = 0 ; j < i; ++ j)
    					ans[count][j] = str[s+j];
    				ans[count][i] = 0;
    				int same = 0;
    				for (int j = 0 ; j < count ; ++ j) 
    				if (!strcmp(ans[j], ans[count])) {
    					same = 1;
    					break;
    				}
    				if (!same) count ++;
    			}
    		}
    		
    		printf("The string '%s' contains %d palindromes.
    ",str,count);
    		/*
    		printf("The %d unique palindromes in 'boy' are",count);
    		for (int i = 0 ; i < count-1 ; ++ i) {
    			printf(" '%s'",ans[i]);
    			if (i < count-2)
    				printf(",");
    			else printf(" and ");
    		}
    		printf("'%s'.
    
    ",ans[count-1]);
    		*/
    	}
    	return 0;
    }
    

    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    二进制或者其他进制转为十进制
    十进制转为二进制或者其他进制
    0.1 + 0.2 !== 0.3
    [git]删除远程分支
    [git]一个本地仓库,多个远程仓库
    [git]用户名,邮箱
    npm install命令
    常用命令:查看端口
    std::lock_guard 与 std::unique_lock
    std::mutex
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4726602.html
Copyright © 2011-2022 走看看