String類函數的使用
一、CF74A-Room Leader
題目:
Sample Input:
5
Petr 3 1 490 920 1000 1200 0
tourist 2 0 490 950 1100 1400 0
Egor 7 0 480 900 950 0 1000
c00lH4x0R 0 10 150 0 0 0 0
some_participant 2 1 450 720 900 0 0
Sample Output:
tourist
Note:
The number of points that each participant from the example earns, are as follows:
Petr — 3860
tourist — 4140
Egor — 4030
c00lH4x0R — - 350
some_participant — 2220
Thus, the leader of the room is tourist.
注意點:
代碼:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
const int N=55;
struct node
{
string name;
int s,u;
int score[6];
int sum;
};
node Data[N];
int main()
{
int n;
int ans=-inf;
int pos=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>Data[i].name;
scanf("%d%d%d%d%d%d%d",&Data[i].s,&Data[i].u,&Data[i].score[1],&Data[i].score[2],&Data[i].score[3],&Data[i].score[4],&Data[i].score[5]);
Data[i].sum=Data[i].score[1]+Data[i].score[2]+Data[i].score[3]+Data[i].score[4]+Data[i].score[5]+100*Data[i].s-50*Data[i].u;
if(Data[i].sum>ans)
{
ans=Data[i].sum;
pos=i;
}
}
cout<<Data[pos].name<<endl;
return 0;
}
二、CF118A-String Task
題目:
Sample Input:
tour
Sample Output:
.t.r
Sample Input:
Codeforces
Sample Output:
.c.d.f.r.c.s
Sample Input:
aBAcAba
Sample Output:
.b.c.b
注意:
代碼:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
int main()
{
string str;
cin>>str;
for(int i=0;i<str.size();i++)
{
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U'||str[i]=='Y'||str[i]=='y') {str.erase(i,1);i--;}
else
{
if(str[i]>='A'&&str[i]<='Z') str[i]=tolower(str[i]);
str.insert(i,".");
i++;
}
}
cout<<str<<endl;
return 0;
}
三、CF112A-Petya and Strings
題目:
Sample Input:
aaaa
aaaA
Sample Output:
0
Sample Input:
abs
Abz
Sample Output:
-1
Sample Input:
abcdefg
AbCdEfF
Sample Output:
1
總結:
代碼:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
transform(s1.begin(),s1.end(),s1.begin(),::tolower);
transform(s2.begin(),s2.end(),s2.begin(),::tolower);
cout<<s1.compare(s2)<<endl;
return 0;
}