7-4 到底有多二 (15分)
一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数,则程度增加0.5倍;如果还是个偶数,则再增加1倍。例如数字-13142223336
是个11位数,其中有3个2,并且是负数,也是偶数,则它的犯二程度计算为:3,约为81.82%。本题就请你计算一个给定整数到底有多二。
输入格式:
输入第一行给出一个不超过50位的整数N
。
输出格式:
在一行中输出N
犯二的程度,保留小数点后两位。
输入样例:
-13142223336
输出样例:
81.82%
https://cloud.tencent.com/developer/article/1535156
1 #include<iostream> 2 using namespace std; 3 int main(){ 4 double k1=1; 5 string n; 6 cin>> n; 7 int len=n.length(); 8 if(n[0]=='-'){ 9 len--; 10 k1+=0.5; 11 //cout<<"fushu"<<endl; 12 } 13 if((n[n.length()-1]-'0')%2==0){ 14 k1*=2; 15 //cout<<"oushu"<<endl; 16 } 17 int count=0; 18 for(int i=0;i<n.length();i++){ 19 if(n[i]=='2'){ 20 count++; 21 //cout<<count<<endl; 22 } 23 } 24 printf("%.2f%%",1.0*count/len*k1*100); 25 return 0; 26 }
7-6 帅到没朋友 (20分)
当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友。本题就要求你找出那些帅到没有朋友的人。
输入格式:
输入第一行给出一个正整数N
(≤),是已知朋友圈的个数;随后N
行,每行首先给出一个正整数K
(≤),为朋友圈中的人数,然后列出一个朋友圈内的所有人——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M
(≤),为待查询的人数;随后一行中列出M
个待查询的ID,以空格分隔。
注意:没有朋友的人可以是根本没安装“朋友圈”,也可以是只有自己一个人在朋友圈的人。虽然有个别自恋狂会自己把自己反复加进朋友圈,但题目保证所有K
超过1的朋友圈里都至少有2个不同的人。
输出格式:
按输入的顺序输出那些帅到没朋友的人。ID间用1个空格分隔,行的首尾不得有多余空格。如果没有人太帅,则输出No one is handsome
。
注意:同一个人可以被查询多次,但只输出一次。
输入样例1:
3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888
输出样例1:
10000 88888 23333
输入样例2:
3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
4
55555 44444 22222 11111
输出样例2:
No one is handsome
https://www.cnblogs.com/littlepage/p/11966811.html
1 #include <iostream> 2 #include <map> 3 #include <vector> 4 using namespace std; 5 int main() 6 { 7 int N,M,T;string tmp; 8 cin>>N; 9 map<string,bool> m; 10 while(N--){ 11 cin>>M; 12 if(M==1) cin>>tmp; 13 else 14 while(M--){ 15 cin>>tmp; 16 m[tmp]=true; 17 } 18 } 19 cin>>T;vector<string> res; 20 map<string,bool> excludeRepeat; 21 while(T--){ 22 cin>>tmp; 23 if(!m[tmp]&&!excludeRepeat[tmp]) res.push_back(tmp); 24 excludeRepeat[tmp]=true; 25 } 26 if(res.size()==0) cout<<"No one is handsome"; 27 else 28 for(int i=0;i<res.size();i++) 29 if(i!=res.size()-1) cout<<res[i]<<" "; 30 else cout<<res[i]; 31 system("pause"); 32 return 0;