Re: 454 Anagrams WA
Posted: Sun Apr 29, 2012 10:54 am
Don't convert copy to lowercase.
Code: Select all
Accepted............. :)
Code: Select all
carthorse = horse cart
carthorse = orchestra
horse cart = orchestra
i do not know u = ok i now donut
carthorse = horse cart
carthorse = orchestra
horse cart = orchestra
i do not know u = ok i now donut
abc = cba
Code: Select all
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int func(string a,string s)
{
int l=a.size(),i;
vector<char>c,c2;
for(i=0; i<l; i++)
{
if(isalpha(a[i]))
{
c.push_back(a[i]);
}
}
sort(c.begin(),c.end());
int l2=s.size();
for(i=0; i<l2; i++)
{
if(isalpha(s[i]))
{
c2.push_back(s[i]);
}
}
sort(c2.begin(),c2.end());
if(c==c2)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int t,i,j,k,g;
string s;
cin>>t;
getchar();
for(i=1; i<=t; i++)
{
vector<string>a,ko;
string t1,t2,t3;
while(getline(cin,s))
{
if(s=="")
{
break;
}
a.push_back(s);
}
for(j=0; j<a.size(); j++)
{
for(k=j+1; k<a.size(); k++)
{
g=func(a[j],a[k]);
if(g==1)
{
t1=a[j];
t2=a[k];
if(t1>t2)
{
t3=t1;
t1=t2;
t2=t3;
}
ko.push_back(t1 + " = "+t2);
}
}
}
sort(ko.begin(),ko.end());
for(int b=0; b<ko.size(); b++)
{
cout<<ko[b]<<endl;
}
cout<<endl;
}
return 0;
}
Code: Select all
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int func(string a,string s)
{
int l=a.size(),i;
vector<char>c,c2;
for(i=0; i<l; i++)
{
if(isalpha(a[i]))
{
c.push_back(a[i]);
}
}
sort(c.begin(),c.end());
int l2=s.size();
for(i=0; i<l2; i++)
{
if(isalpha(s[i]))
{
c2.push_back(s[i]);
}
}
sort(c2.begin(),c2.end());
if(c==c2)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int t,i,j,k,g;
string s;
cin>>t;
getchar();
cout<<endl;
for(i=1; i<=t; i++)
{
vector<string>a,ko;
string t1,t2,t3;
while(getline(cin,s))
{
if(s=="")
{
break;
}
a.push_back(s);
}
for(j=0; j<a.size(); j++)
{
for(k=j+1; k<a.size(); k++)
{
g=func(a[j],a[k]);
if(g==1)
{
t1=a[j];
t2=a[k];
if(t1>t2)
{
t3=t1;
t1=t2;
t2=t3;
}
ko.push_back(t1 + " = "+t2);
}
}
}
sort(ko.begin(),ko.end());
for(int b=0; b<ko.size(); b++)
{
cout<<ko[b]<<endl;
}
cout<<endl;
}
return 0;
}
Code: Select all
2
carthorse
horse
horse cart
orchestra
orchestra
orchestra
i do not know u
ok i now donut
zaaaahari is here
si hari ere h aaaaz
i like tunes
tunes i like
Code: Select all
carthorse = horse cart
carthorse = orchestra
carthorse = orchestra
carthorse = orchestra
horse cart = orchestra
horse cart = orchestra
horse cart = orchestra
i do not know u = ok i now donut
orchestra = orchestra
orchestra = orchestra
orchestra = orchestra
i like tunes = tunes i like
si hari ere h aaaaz = zaaaahari is here
I think you might be nearly there.Angry Bird wrote:Really i'm confused about your ans... Pls give me more I/O.
Code: Select all
cin>>t; getchar();
But you're printing a newline after each case - including the last one.Two consecutive output for two consecutive input is separated by a single blank line.
Code: Select all
/* Read in the number of test cases */
scanf("%d\n",&t);
Code: Select all
if(i != 1) {
cout<<endl;
}