为什么这段代码有问题

pipa-peng 2017-10-30 10:02:46
#include<iostream>
#include<string>
using namespace std;
struct a
{
string l;
int m;
int n;
};
int count1[360],lpo=0;
int main()
{
int co=0;
int count,m1[180],n1[180];
string l1[180];
a b[180];
int count2=1;


cin>>count;
for(int o=0;o<count;o++)
{
cin>>b[o].l>>b[o].m>>b[o].n;
}
cout<<endl;
for(int q=0;q<count;q++)
{

if(b[q].m==b[count2].m&&b[q].n==b[count2].n)
{
count1[co]=q;
count1[co+1]=count2;
co+=2;
lpo++;
}

count2++;
int ui=0;
if(q==count)
{
for(int u=1;u<count;u++)
{
q=u;
ui++;
if(ui==count)
break;
break;
}





}
if(lpo==0)
cout<<"None"<<endl;
}
for(int i=0;i<co;i++)
{
int oplk=0;
if(oplk==0)
{
cout<<b[count1[i]].m<<' '<<b[count1[i]].n<<b[count[i]].l<<' ';
}
else
{
cout<<b[count[i]].l;
}
}
return 0;
}
...全文
125 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
x_xx_xxx_xxxx 2017-10-31
  • 打赏
  • 举报
回复
还有,不是太了解你for循环中,连续用两个break,其中一个在if中。你可能理解错了break的用法。再翻书找找break 、continue 的用法。
x_xx_xxx_xxxx 2017-10-31
  • 打赏
  • 举报
回复
不太懂你的逻辑,也不知道你想要描述什么问题,我copy了你的代码,并编译了一下。报的第一个错,就是count你用成数组了,你是定义的int。我附上了注释,注释下面还有这样的错,自己改一下。如果你是新手,可以试着去学着调试程序,程序员的乐趣,大抵就是完成一段代码后的成就感吧。虽然可能很卑微的成就感。 PS:下次记得描述清楚自己的问题。

#include<iostream>
#include<string>
using namespace std;
struct a
{
 string l;
 int m;
 int n;
};
int count1[360],lpo=0;
int main()
{
	int co=0;
	int count,m1[180],n1[180];
	string l1[180];
	a b[180];
	int count2=1;


	cin>>count;
	for(int o=0;o<count;o++)
	{
 		cin>>b[o].l>>b[o].m>>b[o].n;
	}
	cout<<endl;
	for(int q=0;q<count;q++)
	{
 
 		if(b[q].m==b[count2].m&&b[q].n==b[count2].n)
 		{			
 			count1[co]=q;
 			count1[co+1]=count2;
 			co+=2;
 			lpo++;
 		}
 
 		count2++;
 		int ui=0; 
 		if(q==count)
 		{
 			for(int u=1;u<count;u++)
 			{
 				q=u;
 				ui++;
 				if(ui==count)
 					break;
 				break;
			}
    	}
 		
		 if(lpo==0)
     		cout<<"None"<<endl;
	} 
	
	for(int i=0;i<co;i++)
	{	
		int oplk=0;
		if(oplk==0)
		{
			cout<<b[count1[i]].m<<' '<<b[count1[i]].n<<b[count[i]].l<<' ';   //这里的count 是int 类型,你携程数组了,不太解你想写什么。 
		}
    	else
    	{
    		cout<<b[count[i]].l;
		}
	}
   return 0;
}
他笑他自己 2017-10-31
  • 打赏
  • 举报
回复
连问题都不会描述。谁那么空闲去帮你找?

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧