问题描述
“一只青蛙一张嘴,两只眼睛四条腿。两只青蛙两张嘴,四只眼睛八条腿。
三只青蛙三张嘴,六只眼睛十二条腿。……二十只青蛙二十张嘴,四十只眼睛八十条腿。”
请问上面这段文字,如果完全不省略,全部写出来,从 1 到 20 只青蛙,总共有多少个汉字。
约定:
数字 2 单独出现读成 “两”,在其他数里面读成 “二”,例如 “十二”。
10 读作 “十”,11 读作 “十一”,22 读作 “二十二”。
请只计算汉字的个数,标点符号不计算。
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。
本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
这是一道模拟题
思路:
除了数字以外的文字都是固定的,把变化的数字模拟出来就能算出答案。
这种写法容易出错
这道题最好可以找规律,用运算的方式判断 ans 应该+1 ,+2 还是 +3
小于等于10的时候 ans+1
大于10且小于20 或者 对10取余等于0 的时候 ans+2
其他时候 ans +3
可以使用循环,将嘴,眼睛,个数,腿 分开循环判断求解。
注意:
写完程序的时候,一定要验算,验算,验算 !!!
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
const ll N=1e6;
int ans=0;
int main() {
// cout<<353<<endl;
// return 0;
for(int i=1; i<=20; i++) {
int n=i,e=2*i,l=4*i;
if(n<=10) {
ans++;
} else if(n==20||n==30||n==40||n==50||n==60||n==70||n==80||n==90||n==100)
ans+=2;
else if(n>10&&n<20) {
ans+=2;
} else if(n>=21&&n<100)
ans+=3;
if(e<=10) {
ans++;
} else if(e==20||e==30||e==40||e==50||e==60||e==70||e==80||e==90||e==100)
ans+=2;
else if(e>10&&e<20) {
ans+=2;
} else if(e>=21&&e<100)
ans+=3;
if(l<=10) {
ans++;
} else if(l==20||l==30||l==40||l==50||l==60||l==70||l==80||l==90||l==100)
ans+=2;
else if(l>10&&l<20) {
ans+=2;
} else if(l>=21&&l<100)
ans+=3;
if(i<=10) {
ans++;
} else if(i==20||i==30||i==40||i==50||i==60||i==70||i==80||i==90||i==100)
ans+=2;
else if(i>10&&i<20) {
ans+=2;
} else if(i>=21&&i<100)
ans+=3;
ans+=10;
}
cout<<ans<<endl;
return 0;
}