import java
.text
.DecimalFormat
;
import java
.util
.Scanner
;
public class S7_08 {
static String str
;
static int cnt
;
static int len
;
static double ci
= 1;
static int ou
= 1;
public static void main(String
[] args
) {
DecimalFormat df
= new DecimalFormat("0.00");
Scanner sc
= new Scanner(System
.in
);
str
= sc
.nextLine();
if(str
.charAt(0) == '-') {
len
= str
.length() - 1 ;
ci
+= 0.5;
} else {
len
= str
.length();
}
if ((str
.charAt(str
.length() - 1) - '0') % 2 == 0) ou
+= 1;
for (int i
= 0; i
< str
.length(); i
++) {
if (str
.charAt(i
) - '0' == 2) {
cnt
++;
}
}
System
.out
.println(df
.format(cnt
*1.0/len
*ci
*ou
*100) + "%");
}
}
#include<iostream>
#include<string>
#include<iomanip>
using namespace std
;
int main(){
int len
,w
;
double s
,count
;
string str
;
count
=0;
cin
>>str
;
len
=str
.length();
w
=len
;
for(int i
=0;i
<len
;i
++){
if(str
[i
]=='2'){
count
++;
}
}
if(str
[0]=='-'){
w
--;
if(str
[w
]=='0'||str
[w
]=='2'||str
[w
]=='4'||str
[w
]=='6'||str
[w
]=='8'){
s
=count
/w
*1.5*2;
cout
<<setprecision(2)<<fixed
<<s
*100<<'%';
return 0;
}
else{
s
=count
/w
*1.5;
cout
<<setprecision(2)<<fixed
<<s
*100<<'%';
return 0;
}
}
else if(str
[0]=='+'){
w
--;
if(str
[w
]=='0'||str
[w
]=='2'||str
[w
]=='4'||str
[w
]=='6'||str
[w
]=='8'){
s
=count
/w
*2;
cout
<<setprecision(2)<<fixed
<<s
*100<<'%';
return 0;
}
else{
s
=count
/w
;
cout
<<setprecision(2)<<fixed
<<s
*100<<'%';
return 0;
}
}
else{
if(str
[len
-1]=='0'||str
[len
-1]=='2'||str
[len
-1]=='4'||str
[len
-1]=='6'||str
[len
-1]=='8'){
s
=count
/w
*2;
cout
<<setprecision(2)<<fixed
<<s
*100<<'%';
return 0;
}
else{
s
=count
/w
;
cout
<<setprecision(2)<<fixed
<<s
*100<<'%';
return 0;
}
}
return 0;
}
转载请注明原文地址: https://win8.8miu.com/read-11698.html