LinuxTour's blog

By LinuxTour, history, 3 weeks ago, In English
#include<iostream>

using namespace std;

int main()
{
	int n, mod, result;
	int a[3];
	
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		for(int c=0;c<3;c++)
		{
			cin>>a[c];
		}
		
		for(int j=0;j<3;j++)
		{
			if(a[j] == 1)
			{
				mod = mod + 1;
			}
		}
		
		if(mod == 2 || mod == 3)
		{
			result = result + 1;
			mod = 0;
		}
		
		else
		{
			mod = 0;
		}
	}
	
	cout<<result;
	
	return 0;
}

`

 
 
 
 
  • Vote: I like it
  • -24
  • Vote: I do not like it

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Your code is basically incrementing a non-initialized 'result' variable (so it may contain any random garbage at start) and printing it as the output. The 'mod' variable is also suspicious.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

mod = 0, result = 0?

»
3 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

at first "mod" and "result" do not have values, and then you can 1 to mod, but mod doesn't have value. maybe you should write mod = 0; and result = 0;

also i think that your solution is not correct anyway