![](https://i-blog.csdnimg.cn/blog_migrate/b9431840b120136440235025136712df.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3e1f9eea8b23051dafd3b4939f3f87e3.png)
//之前用数字一直存在测试点过不了,后来看到说要用字符串,因为位数太多了。
#include<stdio.h>
#include<string.h>
int main()
{
char n[50];
scanf("%s", &n);
int num = strlen(n);
int i = 0; int cnt = 0;
for (i = 0; i <num; i++)
{
if (n[i] == '2')
{
cnt++;
}
}
if (n[0] == '-')
{
num -= 1;
}
double result;
result = cnt * 1.0 / num;
if (n[0] == '-')
{
result *= 1.5;
if ((n[num ]-'0') % 2 == 0)
{
result *= 2;
}
}
else if ((n[num-1]-'0') % 2 == 0)
{
result *= 2;
}
result *= 100;
printf("%.2lf%%", result);
return 0;
}
之前的用整型存储
#include<stdio.h>
#include<math.h>
int main()
{
long n,_n;
int cnts=0,cntp = 0;
scanf("%ld", &n);
_n = n;
while (fabs(_n) > 0)
{
if (fabs(_n%10)==2)
{
cntp++;
}
cnts++; _n /= 10;
}
double result = (cntp * 1.0 / cnts);
if (n < 0)
{
result *= 1.5;
}
if (n % 2 == 0) {
result *= 2;
}
result *= 100;
printf("%.2lf%%", result);
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/0c521ce211e3838b192326171df70c6f.png)
也希望大家能指点一下
![](https://i-blog.csdnimg.cn/blog_migrate/adf06c0bc642b2349a1b97c30d90872c.png)
这题要用到结构体数组
#include<stdio.h>
struct student {
int sex;
char name[9];
};
int main()
{
struct student students[50];
int i,j, n;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d %s", &students[i].sex,&students[i].name);
}
for (i = 0; i < n; i++)
{
for (j = n - 1; j > 0; j--)
{
if (students[i].sex != students[j].sex&&students[j].sex!=3)
{
printf("%s %s\n", students[i].name, students[j].name);
students[j].sex = 3; students[i].sex = 3;
break;
}
}
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/5a0cd2e63c69616f6c71ba124e05f1d6.png)
前面三题过于简单,这里不再赘述
![](https://i-blog.csdnimg.cn/blog_migrate/f3d2e536643239c7e0c2abf05f8074d3.png)
#include<stdio.h>
int main()
{
int i,n;
char a[3];
int num1 = 0, num2 = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%s", a);
scanf("%d %d", &num1, &num2);
if ((num1 >= 15 && num1 <= 20) && (num2 >= 50 && num2 <= 70))
{
continue;
}
else printf("%s\n", a);
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/8e0c625c3121a2f7ab19f3d11035bf72.png)
#include<stdio.h>
int main()
{
int num1 = 0,num2 = 0;
scanf("%d %d", &num1, &num2);
int sum = num1 + num2;
int i = 0;
for (i = 0; i < sum; i++)
{
printf("Wang!");
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/29a247eff1403daee90a7b9930b59957.png)
#include<stdio.h>
#include<math.h>
int main()
{
int i, n;
double tall, height;
double sheight;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%lf %lf", &tall, &height);
sheight = (tall - 100) * 0.9;
height /= 2.0;
if (fabs(sheight - height) < sheight * 0.1)
{
printf("You are wan mei!\n");
}
else if (height > sheight)
{
printf("You are tai pang le!\n");
}
else printf("You are tai shou le!\n");
}
return 0;
}