Judge Info

  • Memory Limit: 32768KB
  • Case Time Limit: 10000MS
  • Time Limit: 10000MS
  • Judger: Normal

Description

An anagram is formed by rearranging the letters of a word. You are given a string, please find out if it is an anagram of a word or not. No word will have have more than 50 characters.

Input

The input will consist of a word on one line. The following line contains a number, , of strings to be tested.

Output

For each test string, if the test string is identical to the source string, output 'IDENTICAL', if it is an anagram, output 'ANAGRAM' otherwise output 'NOT AN ANAGRAM', in a single line.

Sample Input

cares
5
scare
races
cares
another
acres

Sample Output

ANAGRAM
ANAGRAM
IDENTICAL
NOT AN ANAGRAM
ANAGRAM

解题思路:字符串数组排序,但是我的方法并不好,只是勉强解出来而已。不过学会了使用qsort函数。

 #include <stdio.h>
#include <string.h>
char A[];
char B[];
char C[]; void swap(char *a,char *b){
char t;
t=*a;
*a=*b;
*b=t;
} int main() {
scanf("%s",A);
int n,flag,i,j;
scanf("%d",&n);
for (i=;i<strlen(A);++i){
C[i]=A[i];
}
while (n--) { scanf("%s",B);
flag=;
for (i=;i<strlen(A);++i) {
if(A[i]!=B[i])
flag=;
}
if(flag==){printf("IDENTICAL\n"); continue;}
for (i=;i<strlen(C)-;++i) {
for (j=i+;j<strlen(C);++j) {
if(B[i]>B[j])
swap(&B[i],&B[j]);
if(C[i]>C[j])
swap(&C[i],&C[j]);
}
} for (i=;i<strlen(A);++i) {
if(C[i]!=B[i])
flag=;
}
if(flag==){printf("ANAGRAM\n"); continue;}
else printf("NOT AN ANAGRAM\n");
}
}

大神解法:

 #include<stdio.h>
#include<stdlib.h>
#include<string.h> char S[]; int cmp(const void *a,const void *b)
{
return *(char *)a-*(char *)b;
} int main()
{
int n,i,len1,len2;
char str[],temp[];
scanf("%s",S);
strcpy(temp,S);
len1=strlen(S);
qsort(S,len1,sizeof(char),cmp);
scanf("%d",&n);
for(i=;i<n;i++)
{
memset(str,,sizeof(str));
scanf("%s",str);
len2=strlen(str);
if(len2!=len1)
{
printf("NOT AN ANAGRAM\n");
continue;
}
if(==strcmp(str,temp))
{
printf("IDENTICAL\n");
continue;
}
else
{
qsort(str,len2,sizeof(char),cmp);
if(==strcmp(S,str))
printf("ANAGRAM\n");
else
printf("NOT AN ANAGRAM\n");
}
}
return ;
}

SZU:A26 Anagram的更多相关文章

  1. [LeetCode] Valid Anagram 验证变位词

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...

  2. Leetcode Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  3. LeetCode 242 Valid Anagram

    Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...

  4. 【09_242】Valid Anagram

    Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...

  5. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

  6. 242. Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  7. (easy)LeetCode 242.Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  8. 【LeetCode】242 - Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  9. Java [Leetcode 242]Valid Anagram

    题目描述: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...

随机推荐

  1. 流动python - 写port扫描仪和各种并发尝试(多线程/多进程/gevent/futures)

    port扫描仪的原理非常easy.没有什么比操作更socket,能够connect它认为,port打开. import socket def scan(port): s = socket.socket ...

  2. Dynamics CRM2013/2015 禁止欢迎屏幕(Disable the Welcome Screen)

    首先打开Dynamic CRM  2013将有一个欢迎界面的例子,下面的图,它不会为了图检查框出现.OK然后,下一次打开就没有. 可是当我们打开F12开发者工具,清除域的缓存后再次打开CRM,这个欢迎 ...

  3. jQuery.extend()方法和jQuery.fn.extend()方法

    jQuery.extend()方法和jQuery.fn.extend()方法源码分析 这两个方法用的是相同的代码,一个用于给jQuery对象或者普通对象合并属性和方法一个是针对jQuery对象的实例, ...

  4. uva757 - Gone Fishing(馋)

    题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...

  5. poj 3254 Corn Fields 国家压缩dp

    意甲冠军: 要在m行n陆行,有一些格您可以种树,别人做不到的.不相邻的树,我问了一些不同的共同拥有的法律. 分析: 从后往前种,子问题向父问题扩展,当种到某一格时仅仅有他和他后面的n-1个格子的情况对 ...

  6. 解决Uploadify上传控件加载导致的GET 404 Not Found问题

    今天在项目发用到Uploadify上传, 发现在打开页面时会有一多余的请求,由于路由没有设置这个,导致404错误,能搜索查到以下解决的方法 <Uploadify v3 bug. Unecessa ...

  7. MVC EF 修改 封装类 通用泛型方法(二)

    修改 这个 方法 如下. 排除 null 值. /// <summary> /// 修改 多数 数据, 个别数据除外, proNames 不写 则是 修改全部 /// </summa ...

  8. 我的MYSQL学习心得(九)

    原文:我的MYSQL学习心得(九) 我的MYSQL学习心得(九) 我的MYSQL学习心得(一) 我的MYSQL学习心得(二) 我的MYSQL学习心得(三) 我的MYSQL学习心得(四) 我的MYSQL ...

  9. mono for android 学习记录

    C#开发Android应用实战(全 扫描 中文版) 学习记录: 拖完控件后,不要急着按F5,需要重新生成,才能自动修改 Resource.Designer.cs 文件 1. Activity 是基于a ...

  10. Delta3D 2.8版本号 预习

    http://blog.csdn.net/zhuyingqingfen/article/details/38581453 看到官网今天的更新.发现即将公布的delta3d 2.8 版本号 做了非常大的 ...