ACM问题 我的代码怎么不对?? http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1658
http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1658Thesedays,Jasonislearn...
http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1658
These days, Jason is learning Design Pattern.There're many patterns and some of them is very hard to understand.He focus on one pattern each day,but he may learn some patterns back and forth several times. After days of study, can you tell me how many patterns has Jason mastered?
Input
The first line is a integer m,(m<=50) standing for the number of test cases.
Each case starts with a integer n(n<=50), number of days.
Then n lines followed.
Each lines contains a string representing the pattern learned in that day.
Please note that some pattern's name may contain blank space and there are no more than 30 characters in a single name.
Output
Print the number of patterns Jason have learned.
Each line for one case.
Sample Input
2
3
SINGLETON
PROTOTYPE
PROTOTYPE
2
FACTORY METHOD
PROXY
Sample Output
2
2
我的代码:
用集合出问题了???
#include<iostream>
#include<set>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
int t,n,i;
char a[100][100];
set<char*> st;
cin>>t;
getchar();
while(t--)
{
cin>>n;
getchar();
for(i=0;i<n;i++)
{
gets(a[i]);
st.insert(a[i]);
}
cout<<st.size()<<endl;
st.clear();
}
return 0;
}
求指教!!!!!!!!!! 展开
These days, Jason is learning Design Pattern.There're many patterns and some of them is very hard to understand.He focus on one pattern each day,but he may learn some patterns back and forth several times. After days of study, can you tell me how many patterns has Jason mastered?
Input
The first line is a integer m,(m<=50) standing for the number of test cases.
Each case starts with a integer n(n<=50), number of days.
Then n lines followed.
Each lines contains a string representing the pattern learned in that day.
Please note that some pattern's name may contain blank space and there are no more than 30 characters in a single name.
Output
Print the number of patterns Jason have learned.
Each line for one case.
Sample Input
2
3
SINGLETON
PROTOTYPE
PROTOTYPE
2
FACTORY METHOD
PROXY
Sample Output
2
2
我的代码:
用集合出问题了???
#include<iostream>
#include<set>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
int t,n,i;
char a[100][100];
set<char*> st;
cin>>t;
getchar();
while(t--)
{
cin>>n;
getchar();
for(i=0;i<n;i++)
{
gets(a[i]);
st.insert(a[i]);
}
cout<<st.size()<<endl;
st.clear();
}
return 0;
}
求指教!!!!!!!!!! 展开
展开全部
你试一下不要把x/y,直接3*x/y,取整输出,你的程序应该是a=(double)x/(double)y;的算法有点问题吧 ,还有一点x/y==1的时候正确答案是.3000000000;
仅供参考:
#include<stdio.h>
int main()
{
int i,t,x,y;
int c[10],sign=0;
double a=0;
char ch;
scanf("%d",&t);
getchar();
while(t--)
{
scanf("%d",&x);
scanf("%c",&ch);
scanf("%d",&y);
a=(double)x/(double)y;
printf(".");
for(i=0;i<10;i++)
{
x=x*3;
c[i]=(int)(x/y);
x=x%y;
printf("%d",c[i]);
}
printf("\n");
}
return 0;
}
仅供参考:
#include<stdio.h>
int main()
{
int i,t,x,y;
int c[10],sign=0;
double a=0;
char ch;
scanf("%d",&t);
getchar();
while(t--)
{
scanf("%d",&x);
scanf("%c",&ch);
scanf("%d",&y);
a=(double)x/(double)y;
printf(".");
for(i=0;i<10;i++)
{
x=x*3;
c[i]=(int)(x/y);
x=x%y;
printf("%d",c[i]);
}
printf("\n");
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我这代码在你们OJ通过了,可能是你们OJ不支持cin和getchar()混合输入吧,毕竟两个的流不一样
#include<iostream>
#include <cstdio>
#include <set>
#include<fstream>
#include<map>
#include <string>
using namespace std;
int main()
{
int T;
scanf("%d",&T);getchar();
while(T--)
{
int n;
scanf("%d",&n);getchar();
set<string> st;
st.clear();
char str[50];
for(int i=0;i<n;i++)
{
gets(str);
st.insert(string(str));
}
printf("%d\n",st.size());
}
return 0;
}
#include<iostream>
#include <cstdio>
#include <set>
#include<fstream>
#include<map>
#include <string>
using namespace std;
int main()
{
int T;
scanf("%d",&T);getchar();
while(T--)
{
int n;
scanf("%d",&n);getchar();
set<string> st;
st.clear();
char str[50];
for(int i=0;i<n;i++)
{
gets(str);
st.insert(string(str));
}
printf("%d\n",st.size());
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ke可能是 因为你进入地方不对 吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-12-24
展开全部
你找一些关于acm的书,自习看看把!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询