有关格式输入输出的问题

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

相关推荐
tryxr1 小时前
矩阵的几种基础变换
java·数据结构·算法·矩阵
mmmmath_31 小时前
LeetCode.028.找出字符串中第一个匹配项的
数据结构·算法·leetcode
Selvaggia1 小时前
DMD(Distribution Matching Distillation,分布匹配蒸馏)
算法
Navigator_Z2 小时前
LeetCode //C - 1255. Maximum Score Words Formed by Letters
c语言·算法·leetcode
All for pursuit.2 小时前
【栈-4】739.每日温度
数据结构·c++·算法·leetcode
All for pursuit.2 小时前
【栈-5】84.柱状图中最大的矩形
数据结构·c++·算法·leetcode
wzdark2 小时前
数据压缩算法的时间复杂度与压缩率权衡4
算法
小陈phd2 小时前
深入理解agent学习笔记(一)——现代agent介绍
人工智能·算法
晴天的雨.9925 小时前
【C++算法】和为s的两个数
开发语言·数据结构·c++·算法
aramae12 小时前
MySQL复合查询(8)
java·c语言·开发语言·后端·算法