莱鸟求教基本问题:怎样在整数型数列中统计连续2个...4,4,....的个数?编程后发现数列的最后一个..4,4..总是被少记数,那位大虾给支招? cout<<"count1="<<count1<<endl;应改为:cout<<"count2="<<count2<<endl; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for(int i=0;i<26;i++){ if (a[i]==4) count++; //统计有几个4连在一起; else { if(count==2) count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过; }} if(count == 1 && a[25] == 4) count2++; cout<<"count1="<<count1<<endl; for(int i=0;i<26;i++){ if (a[i]==4) count++; //统计有几个4连在一起; else { if(count==2) count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过; }} if(count == 1 && a[25] == 4) count2++; cout<<"count1="<<count2<<endl; 试一试:for(int i=0;i<=26;i++){if(i!=26)if (a[i]==4){count++; //统计有几个4连在一起;contenue;}{if(count==2)count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过;}} #include<iostream.h>void main(){int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5,5,5,4,4,5,5,5,5,5,4,4 }; int count2 = 0; int count=0;for(int i=0;i<26;i++){if (a[i]==4)count++; //统计有几个4连在一起;else{if(count==2)count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过;}} if(count==2) count2++;cout<<"count2="<<count2<<endl;} 哈哈犯错误了。同意 itmask(vc&asp) #include<iostream.h>void main(){ int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5 ,5,5,4,4,5,5,5,5,5,4,4 }; int count2 = 0; int count=0; for(int i=0;i<26;i++) { if (a[i]==4) { count++; //统计有几个4连在一起; if(count==2) count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4 } else count=0; //时这里总是被跳过; } cout<<"count="<<count2<<endl;} 也不知道上面会不会串行。输出结果为5,不知道对不对 #include<iostream.h>void main(){ int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5 ,5,5,4,4,5,5,5,5,5,4,4 }; int count2 = 0; int count=0; for(int i=0;i<26;i++) { while (a[i]==4 &&i<26) { count++; i++; } if(count==2) count2++; count=0; } cout<<"count="<<count2<<endl;} 这会的结果为4!!!!! #include<iostream.h>void main(){ int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5,5,5,4,4,5,5,5,5,5,4,4 }; int count2 = 0; int count=0; for(int i=0;i<26;i++) { if (a[i]==4) count++; //统计有几个4连在一起; else count = 0; if(count==2) { count2++; //统计2个4连在一起的有几个。 count=0; } } cout<<"count1="<<count2<<endl;} 或#include<iostream.h>void main(){ int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5,5,5,4,4,5,5,5,5,5,4,4 }; int count2 = 0; int count=0; for(int i=1;i<26;i++) { if (a[i]==4 && a[i-1]==4) { count2++; //统计2个4连在一起的有几个。 i++; } } cout<<"count1="<<count2<<endl;} 处理WM_SETTEXT消息的尴尬 线程创建类问题 如何高效的移动文件中的整块数据? 一个简单的def问题? Component和Object的本质区别是什么? 郁闷 …… 哪里有COM的例子?尽可能简单的例子。 VC初学者必看-VC在线教程 "迭代子'什么意思? 各位老大帮帮!!!!!!!! 找qq的工具。。。。。看隐身好友的。 CWnd很少用,有些地方弄不明白。 老大:Node<T>这个是什么意思?MSDN也没说,还有template <class T>又是什么意思?小弟不明白
{
if (a[i]==4)
count++; //统计有几个4连在一起;
else
{
if(count==2)
count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过;
}
}
if(count == 1 && a[25] == 4)
count2++;
cout<<"count1="<<count1<<endl;
{
if (a[i]==4)
count++; //统计有几个4连在一起;
else
{
if(count==2)
count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过;
}
}
if(count == 1 && a[25] == 4)
count2++;
cout<<"count1="<<count2<<endl;
{
if(i!=26)
if (a[i]==4)
{
count++; //统计有几个4连在一起;
contenue;
}
{if(count==2)
count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过;
}
}
void main()
{int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5,5,5,4,4,5,5,5,5,5,4,4 };
int count2 = 0; int count=0;
for(int i=0;i<26;i++)
{if (a[i]==4)
count++; //统计有几个4连在一起;else
{if(count==2)
count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4count=0; //时这里总是被跳过;
}
} if(count==2)
count2++;
cout<<"count2="<<count2<<endl;}
同意 itmask(vc&asp)
#include<iostream.h>
void main()
{
int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5
,5,5,4,4,5,5,5,5,5,4,4 };
int count2 = 0; int count=0;
for(int i=0;i<26;i++)
{
if (a[i]==4)
{
count++; //统计有几个4连在一起;
if(count==2)
count2++; //统计2个4连在一起的有几个。在debuger时发现,最后一个4,4
}
else
count=0; //时这里总是被跳过;
} cout<<"count="<<count2<<endl;}
也不知道上面会不会串行。输出结果为5,不知道对不对
void main()
{
int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5
,5,5,4,4,5,5,5,5,5,4,4 };
int count2 = 0; int count=0;
for(int i=0;i<26;i++)
{
while (a[i]==4 &&i<26)
{
count++;
i++;
}
if(count==2)
count2++;
count=0;
} cout<<"count="<<count2<<endl;}
这会的结果为4!!!!!
void main()
{
int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5,5,5,4,4,5,5,5,5,5,4,4 };
int count2 = 0; int count=0;
for(int i=0;i<26;i++)
{
if (a[i]==4)
count++; //统计有几个4连在一起;
else
count = 0; if(count==2)
{
count2++; //统计2个4连在一起的有几个。
count=0;
}
} cout<<"count1="<<count2<<endl;
}
#include<iostream.h>
void main()
{
int a[26]={5,4,4,5,5,4,4,4,5,5,5,4,4,5,5,5,5,4,4,5,5,5,5,5,4,4 };
int count2 = 0; int count=0;
for(int i=1;i<26;i++)
{
if (a[i]==4 && a[i-1]==4)
{
count2++; //统计2个4连在一起的有几个。
i++;
}
} cout<<"count1="<<count2<<endl;
}