问题 D: No Duplicates

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:47   1429   0

问题 D: No Duplicates

时间限制: 1 Sec 内存限制: 128 MB
提交: 68 解决: 45
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

There is a game in which you try not to repeat a word while your opponent tries to see if you have repeated one.
"THE RAIN IN SPAIN" has no repeats.
"IN THE RAIN AND THE SNOW" repeats THE.
"THE RAIN IN SPAIN IN THE PLAIN" repeats THE and IN.
Write a program to test a phrase.

输入

Input is a line containing words separated by single spaces, where a word consists of one or more uppercase letters. A line contains no more than 80 characters.

输出

The output is "yes" if no word is repeated, and "no" if one or more words repeat.

样例输入

THE RAIN IN SPAIN

样例输出

yes

提示


代码:

#include <iostream>

#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
char str[105];
gets(str);
int len = strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]>='a'&&str[i]<='z')
{
str[i]=str[i]-'a'+'A';
}
}
//puts(str);
char s[105][105];
int cnt = 0;
int t = 0;
for(int i=0;i<len;i++)
{
if(str[i]==' '||str[i]=='\0')
{
s[cnt][t]='\0';
t = 0;
cnt++;
}
else
{
s[cnt][t] = str[i];
t++;
}
}
// for(int i=0;i<=cnt;i++)
// {
// printf("%s\n",s[i]);
// }
for(int i=0;i<cnt;i++)
{
for(int j=i+1;j<=cnt;j++)
{
if(strcmp(s[i],s[j])==0)
{
printf("no");
return 0;
}
}
}
printf("yes");
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP