141A
题目
可笑的笑话
链接:https://codeforces.com/problemset/problem/141/A
分析
读完这道题我第一反应就是用map集合来做,因为涉及到了字符数字个数的比较,让我联想到了键值对,先统计前两行字母,在创建一个map存放堆中字母个数,然后再比较俩个map相同key对应的value。
代码实现
1 #include<iostream> 2 #include<map> 3 #include<string> 4 using namespace std; 5 int main() { 6 string gname,oname,Dui; 7 string str = "NEWYEARANDCHRISTMASMEN"; 8 cin >> gname; 9 cin >> oname; 10 cin >> Dui; 11 map<char, int> charmap; 12 map<char, int> D; 13 for (int i = 0; i < 26; i++) 14 { 15 charmap[char('A' + i)] = 0; 16 D[char('A' + i)] = 0; 17 } 18 int glength = gname.length(); 19 int olength = oname.length(); 20 map<char, int>::iterator iterc,iterd; 21 for (int i = 0; i < glength; i++) 22 { 23 charmap[gname[i]]++; 24 25 } 26 /* 27 while(iter!=charmap.end()) 28 { 29 cout << iter->first << " " << iter->second << endl; 30 iter++; 31 }*/ 32 for (int i = 0; i < olength; i++) 33 { 34 charmap[oname[i]]++; 35 } 36 for (int i = 0; i < Dui.length(); i++) 37 { 38 D[Dui[i]]++; 39 } 40 iterc = charmap.begin(); 41 iterd = D.begin(); 42 int flag = 0; 43 while (iterc != charmap.end() && iterd != D.end()) 44 { 45 if (iterc->second != iterd->second) 46 { 47 cout << "NO"<<endl; 48 //cout << iterc->second << "²»µÈÓÚ" << iterd->second; 49 flag = 1; 50 break; 51 } 52 iterc++; 53 iterd++; 54 55 } 56 /*for (int i = 0; i < str.length(); i++) 57 { 58 if (!D[str[i]]&&!flag) 59 { 60 cout << "NO"; 61 cout << str[i] << "=" << 0; 62 flag = 1; 63 break; 64 } 65 }*/ 66 if (!flag) 67 cout << "YES"<<endl; 68 69 70 return 0; 71 }
1368A
题目
C+=
链接:https://codeforces.com/problemset/problem/1368/A
分析
这道题目非常简单,小小的贪心思路,总是用当前较小的数加上当前最大的数,这样得到相加的次数就是最小的。(最快达到a或者b大于n)
代码实现
1 #include<iostream> 2 using namespace std; 3 #define MAXSize 100 4 int mymin(int a,int b) 5 { 6 if(a>b) 7 return b; 8 else 9 return a; 10 } 11 int main() 12 { 13 int a[MAXSize],b[MAXSize],n[MAXSize],m; 14 cin>>m; 15 for(int i=0;i<m;i++) 16 { 17 cin>>a[i]>>b[i]>>n[i]; 18 } 19 for(int i=0;i<m;i++) 20 { 21 int count = 0; 22 while(a[i]<=n[i]&&b[i]<=n[i]) 23 { 24 if(b[i]==mymin(a[i],b[i])) 25 { 26 b[i]+=a[i]; 27 count++; 28 } 29 else 30 { 31 a[i]+=b[i]; 32 count++; 33 } 34 } 35 cout<<count<<endl; 36 } 37 return 0; 38 }