zoukankan      html  css  js  c++  java
  • UVA156 Ananagrams

    题目描写的乱七八糟 就是找无论顺序大小写 不重复出现的字符串 按字典序输出

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=92

    代码乱七八糟的写的真长

    View Code
      1 #include <stdio.h>
      2 #include<string.h>
      3 #include<stdlib.h>
      4 typedef struct node
      5 {
      6     char c[25];
      7     int x;
      8 }st;
      9 st q[10001];
     10 int Comp(const void *p1,const void *p2)
     11 {
     12 return strcmp((char *)p1,(char *)p2);
     13 }
     14 int re(char x[],char y[])
     15 {
     16     int i,a[300],b[300],flag = 1;
     17     char d1[25],d2[25];
     18     memset(a,0,sizeof(a));
     19     memset(b,0,sizeof(b));
     20     if(strlen(x)==strlen(y))
     21     {
     22         for(i = 0 ; i < strlen(x) ; i++)
     23         {
     24             if(x[i]>='a'&&x[i]<='z')
     25             d1[i] = x[i]-32;
     26             else
     27             d1[i] = x[i];
     28             if(y[i]>='a'&&y[i]<='z')
     29             d2[i] = y[i]-32;
     30             else
     31             d2[i] = y[i];
     32            a[d1[i]]++;
     33            b[d2[i]]++;
     34         }
     35         for(i = 0 ; i < strlen(x) ; i++)
     36         {
     37             if(x[i]>='a'&&x[i]<='z')
     38             d1[i] = x[i]-32;
     39             if(a[d1[i]]!=b[d1[i]])
     40             {
     41                 flag = 0;
     42                 break;
     43             }
     44         }
     45         if(flag)
     46         return 1;
     47         else
     48         return 0;
     49     }
     50     else
     51     return 0;
     52 }
     53 int main()
     54 {
     55     int i, j, k, m=0,num,d =0, flag,y,n;
     56     char str[1001],str1[1001][25];
     57     memset(q,0,sizeof(q));
     58     while(gets(str)!=NULL)
     59     {
     60         if(str[0]=='#')
     61         break;
     62         k = strlen(str);
     63         flag = 0;
     64         y = 0;
     65         for(i = 0 ; i < k ; i++)
     66         {
     67             if(str[i]!=' ')
     68             {
     69                 flag = 1;
     70                 q[d].c[y] = str[i];
     71                 y++;
     72             }
     73             else if(flag)
     74             {
     75                 q[d].c[y]='\0';
     76                 d++;
     77                 y = 0;
     78                 flag = 0;
     79             }
     80         }
     81         if(str[k-1]!=' ')
     82         {
     83             q[d].c[y]='\0';
     84             d++;
     85             y = 0;
     86             flag = 0;
     87         }
     88     }
     89     if(!flag)
     90     n = d-1;
     91     else
     92     n = d;
     93     for(i = 0 ; i < d ; i++)
     94     for(j = i+1 ; j < d ; j++)
     95     {
     96         if(re(q[i].c,q[j].c))
     97         {
     98             q[i].x = 1;
     99             q[j].x = 1;
    100         }
    101     }
    102     int w = 0;
    103     for(i = 0 ; i < d ; i++)
    104     if(!q[i].x)
    105     {
    106         strcpy(str1[w],q[i].c);
    107         w++;
    108     }
    109     qsort(str1,w,sizeof(str1[0]),Comp);
    110     for(i = 0 ;i < w ; i++)
    111     puts(str1[i]);
    112     return 0;
    113 }
  • 相关阅读:
    configure.ac:91: error: possibly undefined macro: AC_SEARCH_LIBS
    debian上安装tmux
    ssh: Bad configuration option: usedns
    mysql启动失败“MySQL Daemon failed to start”
    批量查询文件的编码格式
    mysql计算QPS
    网络资源汇总
    jQuery Mobile + HTML5
    配置SQL Server 2008 R2 Reporting Services
    分享一个C#创建Barcode的DLL
  • 原文地址:https://www.cnblogs.com/shangyu/p/2590945.html
Copyright © 2011-2022 走看看