有关格式输入输出的问题

对于格式输入输出问题,我们最好用c语言编写代码!!!

成绩统计

难点:格式化输出

cpp 复制代码
#include <cstdio>
using namespace std;
typedef long long ll;

ll n,score,a,b;

int main()
{
  //及格>=60 优秀>=85 求及格率=及格人数/总人数
  //要求格式输出:%f 四舍五入:num*1.0/sum;百分符号前:num*100.0/sum
  scanf("%lld",&n);
  ll t=n;
  while(n--){
    scanf("%lld",&score);
    if(score>=60)
    a++;
    if(score>=85)
    b++;
  }
  printf("%.f%\n%.f%%",a*100.0/t,b*100.0/t);
  return 0;
}

单词逆序

cpp 复制代码
#include <cstdio>
#include <cstring>
using namespace std;

//要实现内部间的单词排序,我们最好用二维数组存储
int main(){
   char str[1000][20];
   int num=0;//装长度
   //无限读入字符
   while(scanf("%s",str[num])!=EOF){
      num++;
   }
   for(int i=0;i<num;i++){
      int len=strlen(str[i]);//c语言中求字符串长
      for(int j=len-1;j>=0;--j){
         printf("%c",str[i][j]);//格式输出-%c-字符输出
      }
      //格式输出:每行之间用空格隔开,行末不输出
      if(i<num-1) printf(" ");
   }
   return 0;
}

用c++编译注意

1.typedef long long ll;//全用long型,防止溢出

2.提升cin输入输出速度:

ios::sync_with_stdio(0);

cin.tie(0);

cout.tie(0);//但输出时,我们最好用\n输出

#define endl '\n' 此时不要用scanf与printf

3.正无穷的定义

#define INF 0x3f3f3f3f //四个字节-int型的无穷

#define INF 0x3f3f3f3f3f3f3f3f //8个字节-int型的无穷

相关推荐
sali-tec6 小时前
C# 基于halcon的视觉工作流-章66 四目匹配
开发语言·人工智能·数码相机·算法·计算机视觉·c#
小明说Java6 小时前
常见排序算法的实现
数据结构·算法·排序算法
行云流水20197 小时前
编程竞赛算法选择:理解时间复杂度提升解题效率
算法
smj2302_796826528 小时前
解决leetcode第3768题.固定长度子数组中的最小逆序对数目
python·算法·leetcode
cynicme9 小时前
力扣3531——统计被覆盖的建筑
算法·leetcode
core5129 小时前
深度解析DeepSeek-R1中GRPO强化学习算法
人工智能·算法·机器学习·deepseek·grpo
mit6.8249 小时前
计数if|
算法
a伊雪10 小时前
c++ 引用参数
c++·算法
Data_agent10 小时前
1688获得1688店铺列表API,python请求示例
开发语言·python·算法
2301_7644413311 小时前
使用python构建的应急物资代储博弈模型
开发语言·python·算法