-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathleetcode3.cpp
More file actions
33 lines (33 loc) · 765 Bytes
/
Copy pathleetcode3.cpp
File metadata and controls
33 lines (33 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
using namespace std;
bool canConstruct(string ransomNote, string magazine)
{
int count=ransomNote.length(),j,i;
for( i=0;i<ransomNote.length();i++)
{
cout<<count;
if(count==0)
return true;
for( j=0;j<magazine.length();j++)
{
if(magazine[j]==ransomNote[i])
{
magazine[j]='*';
count-=1;
break;
}
}
cout<<"\n"<<j;
if(j==magazine.length())
return false;
}
if(count==0)
return true;
return false;
}
int main()
{
string r,m;
cin>>r>>m;
cout<<canConstruct(r,m);
}