http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=832
Examples:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void* a,const void* b)
{
return *(int *)a - *(int *)b;//由小到大排
}
int main()
{
char s1[110], s2[110];
while (scanf("%s%s", s1, s2) != EOF)
{
int a[26] = {0}, b[26] = {0}, i;
for (i = 0; s1[i]; i++)
a[s1[i]-'A']++;
for (i = 0; s2[i]; i++)
b[s2[i]-'A']++;
qsort(a, 26, sizeof(int), cmp);
qsort(b, 26, sizeof(int), cmp);
// for(int j=0;j<26;j++)
// {
// printf("%d ",a[j]);
//
//
// }
// printf("\n");
// for(j=0;j<26;j++)
// {
// printf("%d ",b[j]);
//
// }
// printf("\n");
printf("%s\n", memcmp(a, b, sizeof(a))?"NO":"YES");
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define maxn 100
int left,chance;//猜left个位置
char s[maxn],s2[maxn];
int win,lose;
void guess(char ch)
{
int bad = 1;
for(int i = 0;i < strlen(s);i++)
{
if (s[i] == ch)//猜对
{
left--;
s[i] = ' ';//把猜对的对应字母置为空;以解决猜过的字母再猜一次算错
bad = 0;
}
}
if (bad)//无符合字母
{
--chance;
}
if (!chance)//无机会
{
lose = 1;
}
if (!left)//猜对
{
win = 1;
}
}
int main()
{
int rnd;
while(scanf("%d%s%s",&rnd,s,s2) == 3 && rnd != -1)
{
printf("Round %d\n",rnd);
win = lose =0;//求解新数据要初始化
left = strlen(s);
chance = 7;
for(int i = 0;i < strlen(s2);i++)
{
guess(s2[i]);
if (win || lose)
{
break;
}
}
if (win)
{
printf("You win.\n");
}
else if (lose)
{
printf("You lose.\n");
}
else
printf("You chickened out.\n");
}
return 0;
}
#include <stdio.h>
#define maxn 25
int n,k,m,a[maxn];
int go(int p,int d,int t)
{
while(t--)
{
do
{
p = (p + d + n - 1) % n + 1;//d + n - 1逆时针等于10,顺时针等于8
} while (a[p] == 0);//a[p]不为0就t--;是0就跳过
}
return p;
}
int main()
{
while(scanf("%d%d%d",&n,&k,&m) == 3 && n)
{
for(int i = 1;i <= n;i++)
{
a[i] = i;
}
int left = n;
int p1 = n,p2 = 1;
while(left)
{
p1 = go(p1,1,k);//逆时针走
p2 = go(p2,-1,m);//顺时针走
printf("%3d",p1);//每个数占3个位置
left--;
if (p2 != p1)
{
printf("%3d",p2);
left--;
}
a[p1] = a[p2] = 0;
if (left)
{
printf(",");
}
}
printf("\n");
}
return 0;
}
213 - Message Decoding