HDU2072

          这题WA了多次。

         主要有四方面的问题:①题目说每篇小文章占一行,也就是说每篇文章的字符总数不大于80。(猜想:控制台每行为80个字符长度,之前也有类似一题,

   也是采取80个字符长度,AC了。)②测试数据,应该说每次都会在测试数据上出点问题,花的时间最多的也是调试程序。编写程序之前应该考虑程序对边界数据的处理!

   ③题目说:遇到“#"输入结束是指输入”#“之后,程序结束。并不是每行输入结束的标志!④操作字符串的能力急待提高!

 

          给出一组测试数据:

                                        you are my friend (you之前和friend 之后均无空格)

                                                you are my friend(you之前空格数大于1)

                                        you are          my friend(are和my之前空格数多于1)

                                        you are my friend                         (friend之后有很多空格)

                                        #

 

                                        4

                                        4

                                        4

                                        4

 

 

        贴上我的代码:

    

#include
#include
using namespace std;

int main () 
{
   char *c=NULL,*d=NULL;  //指针初始化!!!
   char a[81];
   char b[41][81];
   int i,j,k,len,count;

   while(gets(a))
   {
	   if(a[0]=='#') break;

	   len=strlen(a);
	   for(i=len-1;i>=0;i--)  //最后的空格,去掉
	   {
		   if(a[i]==' ')
			   a[i]=NULL;
		   else
			   break;
	   }

	   len=strlen(a);
	   for(i=0;i


    


    

       还有一个简单的代码,用到了STL中的set。(个人认为初学者不能过多依赖库中的东西,自己多练习。)

       代码如下(非本人写出,源自网络):

#include
#include
#include
#include
using namespace std;

set temp;

int main()
{
	string row,input;

	while( getline(cin,row) && row!="#" )
	{
		temp.clear();

		stringstream str(row);

		while(str>>input)
			temp.insert(input);

		cout<


 

     欢迎拍砖!

    

        

                               

                          

 

 

                                                           

你可能感兴趣的:(HDU)