2125 very simple
This commit is contained in:
		
							
								
								
									
										43
									
								
								2125-20240103-pass/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								2125-20240103-pass/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| #include<stdcpp.h> | ||||
| using namespace std; | ||||
| class Solution{ | ||||
|     public: | ||||
|     int numberOfBeams(vector<string> & bank){ | ||||
|         int len = bank.size(); | ||||
|         vector<string> null_bank; | ||||
|         for(string row_plan: bank){ | ||||
|             bool flag = 1; | ||||
|             for(char ch: row_plan){ | ||||
|                 if(ch == '1'){ | ||||
|                     flag = 0; | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|             if(!flag) null_bank.push_back(row_plan); | ||||
|         } | ||||
|         long long ans = 0; | ||||
|         int last = 0; | ||||
|         for(string row_plan: null_bank){ | ||||
|             int num = 0; | ||||
|             for(char ch : row_plan){ | ||||
|                 if(ch == '1')   num++; | ||||
|             } | ||||
|             ans += num*last; | ||||
|             last = num; | ||||
|         } | ||||
|         return ans; | ||||
|     } | ||||
|      | ||||
| }; | ||||
|  | ||||
| int main(){ | ||||
|     Solution sol; | ||||
|     vector<string> ex1 = {"011001","000000","010100","001000"}; | ||||
|     cout<<"ex1"<<endl; | ||||
|     cout<<sol.numberOfBeams(ex1)<<endl; | ||||
|  | ||||
|     vector<string> ex2 = {"000","000","000"}; | ||||
|     cout<<"ex2"<<endl; | ||||
|     cout<<sol.numberOfBeams(ex2)<<endl; | ||||
|     return 0; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user