i fixed it and got AC.your program must be CaSe InSeNsItIvE
thanx anyway.

Moderator: Board moderators
Code: Select all
aaa a
Code: Select all
aaa a
Code: Select all
//code remove
Code: Select all
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define MAX 5001
using namespace std;
int comp(const void *a, const void *b)
{
return strcmp((char *)a,(char *)b);
}
int main(){
char str[2000],*p;
char word[MAX][100];
char dil[] = " .:,\"'";
int k = 0,i,j;
//freopen("in.txt","rt",stdin);
while(scanf("%s",str) == 1){
p = strtok(str,dil);
if(p)
strcpy(word[k++],p);
while(p){
p = strtok(NULL,dil);
if(p)
strcpy(word[k++],p);
}
}
for(i = 0; i<k; i++){
for(j = 0;word[i][j]; j++){
word[i][j] = tolower(word[i][j]);
}
}
qsort(word,k,sizeof(word[0]),comp);
for(i = 1; i < k+1; i++){
if(strcmp(word[i],word[i-1]))
printf("%s\n",word[i-1]);
}
return 0;
}
I think words are allowed to be up to 200 characters long by problem's text. And since it seems like you're using C++ anyway, why not just use std::string to keep strings?char word[MAX][100];
That's not going to solve the problem.char dil[] = " .:,\"'";
Code: Select all
string word;
vector<string> dic;
char symbol = getchar();
while (symbol != EOF)
{
if (isalpha(symbol)) // convert 'symbol' to lowercase if necessary and append it to the end of
// 'word'
else // add 'word' to the vector and sort it if 'word' is not in it yet and finally clear the
// auxiliary string
symbol = getchar();
}
Code: Select all
string str;
while(getline(cin,str,'\n'))
{
.......then just take words ....
}
char str[300];
while(gets(str))
{
.......
}
Code: Select all
char S[20000][300];
char str[300];
char s[300];
while(scanf("%s",str)==1)
{
k=0;
word=0;
for(i=0;str[i];i++)
{
if(isalpha(str[i]))
{
ch=tolower(str[i]);
s[k]=ch;
k++;
word=1;
}
else
{
if(word==1)
{
s[k]='\0';
strcpy(S[l],s);
l++;
word=0;
k=0;
}
}
}
if(word==1)
{
s[k]='\0';
strcpy(S[l],s);
l++;
}
}
Code: Select all
while((getline(cin,st))!=NULL)
{
strcpy(ch,st.c_str());
for(int i=0;i<(int)strlen(ch);i++)
{
if(!isalpha(ch[i]))
ch[i]=' ';
else if(isalpha(ch[i]) && isupper(ch[i])) ch[i]=tolower(ch[i]); //making all lower case
}
parse(ch);
}
//parse the char arr using strtok. there are only space char and tab char. Now it is easy to parse
Code: Select all
#include<stdio.h>
#include<string.h>
void ch_sort(char str[5000][201],int n);
int main()
{
int n=0,i,j,tag=1;
char a[5000][201],b[5000][201];
while(gets(a[n++]))
for(i=0;i<n;i++)
{
for(j=0;a[i][j]!='\0';j++)
{
if(a[i][j]>='A'&&a[i][j]<='Z')
a[i][j]+=32;
}
}
int k=0,l;
for(i=0;i<n;i++)
{
l=0;
tag=0;
for(j=0;a[i][j]!='\0';j++)
{
if(a[i][j]>='a'&&a[i][j]<='z')
{
b[k][l++]=a[i][j];
tag=1;
}
else
{
if(tag==1)
{
b[k][l]='\0';
k++;
l=0;
tag=0;
}
}
}
if(tag==1)
{
b[k][l]='\0';
k++;
l=0;
tag=0;
}
}
ch_sort(b,k);
for(i=0;i<k;i++)
{
if(b[i][0]!='\0')
puts(b[i]);
}
return 0;
}
void ch_sort(char str[5000][201],int n)
{
char dummy[201];
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<=n-i-1;j++)
{
if(strcmp(str[j],str[j+1])>0)
{
strcpy(dummy,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],dummy);
}
if(strcmp(str[j],str[j+1])==0)
str[j+1][0]='\0';
}
}
return;
}