有关格式输入输出的问题

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

相关推荐
liruiqiang0510 分钟前
机器学习 - 投票感知器
人工智能·算法·机器学习
学编程的小程5 小时前
LeetCode216
算法·深度优先
leeyayai_xixihah5 小时前
2.21力扣-回溯组合
算法·leetcode·职场和发展
01_5 小时前
力扣hot100——相交,回文链表
算法·leetcode·链表·双指针
萌の鱼5 小时前
leetcode 2826. 将三个组排序
数据结构·c++·算法·leetcode
Buling_05 小时前
算法-哈希表篇08-四数之和
数据结构·算法·散列表
AllowM5 小时前
【LeetCode Hot100】除自身以外数组的乘积|左右乘积列表,Java实现!图解+代码,小白也能秒懂!
java·算法·leetcode
RAN_PAND6 小时前
STL介绍1:vector、pair、string、queue、map
开发语言·c++·算法
fai厅的秃头姐!8 小时前
C语言03
c语言·数据结构·算法
lisanndesu8 小时前
动态规划
算法·动态规划