有关格式输入输出的问题

对于格式输入输出问题,我们最好用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型的无穷

相关推荐
l1t8 分钟前
Javascript引擎node bun deno比较
开发语言·javascript·算法·ecmascript·bun·精确覆盖·teris
仰泳的熊猫24 分钟前
1094 The Largest Generation
数据结构·c++·算法·pat考试
LYFlied25 分钟前
【每日算法】LeetCode 739. 每日温度:从暴力遍历到单调栈的优雅解决
前端·算法·leetcode·面试·职场和发展
铭哥的编程日记27 分钟前
DFS + 剪枝 解决 全排列系列问题 (所有题型)
算法·深度优先·剪枝
yaoh.wang27 分钟前
力扣(LeetCode) 67: 二进制求和 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
Java后端的Ai之路27 分钟前
【分析式AI】-LightGBM算法命名解释
人工智能·算法·机器学习·aigc·分析式ai
夏鹏今天学习了吗34 分钟前
【LeetCode热题100(74/100)】跳跃游戏
算法·leetcode·游戏
CoovallyAIHub34 分钟前
夜间、远距离都不怕!新型无人机识别算法准确率超92%
深度学习·算法·计算机视觉
小年糕是糕手44 分钟前
【C++】string类(二)
开发语言·数据结构·c++·程序人生·算法·leetcode·数字货币
Tisfy1 小时前
LeetCode 3573.买卖股票的最佳时机 V:深度优先搜索
算法·leetcode·深度优先