题目链接:codeforces 722B
题意:
给出 n 个字符串,判断元音个数是否等于输入的个数(题目中元音为 : ' a ' ,' e ', ' i ' , ' o ', ' u ', ' y ' )
AC代码
c++:
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, f = 1;
cin >> n;
int a[105];
char s[105];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
getchar();
for(int i = 1; i <= n; i++){
gets(s);
int len = strlen(s), num = 0;
for(int j = 0; j < len; j++){
if(s[j]=='a'||s[j]=='e'||s[j]=='i'||s[j]=='o'||s[j]=='u'||s[j]=='y'){
num++;
}
}
if(num != a[i]){
f = 0;
}
}
if(f == 0){
cout << "NO" << endl;
}
else{
cout << "YES" << endl;
}
return 0;
}
php:
<?php
$cin = fopen("php://stdin", "r");
$n = intval(fgets($cin));
$s = fgets($cin);
$s = str_replace(PHP_EOL, '', $s);
$a = explode(' ', $s);
$f = 1;
for($i = 0; $i < $n; $i++){
$s = fgets($cin);
$num = 0;
for($j = 0; $j < strlen($s); $j++){
if($s[$j]=='a'||$s[$j]=='e'||$s[$j]=='i'||$s[$j]=='o'||$s[$j]=='u'||$s[$j]=='y'){
$num++;
}
}
if($num != $a[$i]){
$f = 0;
}
}
if($f == 0){
print_r("NO"."\n");
}
else{
print_r("YES"."\n");
}
fclose($cin);
?>