Problem 45 What Time Is It

博客围绕将数字形式的时间转换成文字形式的问题展开,指出所有规则已给出,编码时需全面考虑,避免遗漏情况。

这个问题是要求把数字形式的时间转换成文字形式的。所有的regulation都给出了,编码的时候小心一点考虑全面就是了。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
 
 string exp;
 
 int hr, min;
 char dump;
 ifstream fin("clock.in");
 fin>>hr>>dump>>min;

 string hour[] = {"one", "two", "three", "four",
      "five","six", "seven", "eight",
      "nine","ten", "eleven","twelve"};

 string minute[] = {" o'clock", "one", "two", "three",
        "four", "five","six", "seven",
        "eight", "nine", "ten", "eleven",
        "twelve", "thirteen", "fourteen",
        "fifteen","sixteen", "seventeen",
        "eighteen","nineteen"};

 string key[] = {"twenty", "thirty", "forty"};
 
 switch(min){
  case 0:
   exp = hour[hr - 1] + minute[min];
   break;
  case 15:
   exp = "quarter past " + hour[hr - 1];
   break;
  case 30:
   exp = hour[hr - 1] + " thirty";
   break;
  case 45:
   exp = "quarter to " + hour[hr % 12];
   break;
  default:
   if(min < 20) exp = hour[hr - 1] + " " + minute[min];
   else if(min > 45)
    exp = minute[60 - min] + " to " + hour[hr % 12];
   else{
    exp = hour[hr - 1] + " " + key[min / 10 - 2];
    if(min % 10) exp = exp + "-" + minute[min % 10];
   }
   break;
 }
 
 // ASCII code: 'A' = 65, 'a' = 97
 exp[0] = exp[0] - (97 - 65);
 ofstream fout("clock.out");
 fout<<exp<<endl;
}

### Differences Among Benchmark, Profiling, Tracing, and Monitoring in Software Performance Analysis In software performance analysis, benchmarking, profiling, tracing, and monitoring are distinct but complementary techniques that serve different purposes. Below is an explanation of each concept and their differences: #### Benchmark Benchmarking involves measuring the performance of a system or application under specific conditions to establish a baseline for comparison. This technique focuses on quantifying performance metrics such as throughput, latency, or resource utilization over a defined workload. The results of benchmarking can be used to evaluate the efficiency of an application or compare it against other systems. For example, tools like `iperf(1)` are often used to benchmark network performance[^2]. #### Profiling Profiling is the process of analyzing the runtime behavior of a program to identify performance bottlenecks. It typically involves collecting detailed data about function calls, execution time, memory usage, and CPU cycles. Visualization tools like flame graphs are commonly used to represent profiling data, helping developers pinpoint areas where optimizations can be made. Profiling provides deeper insights into how an application uses resources during its execution. #### Tracing Tracing refers to the continuous recording of events occurring within a system or application. These events may include function calls, system calls, or hardware interrupts. Tracing is particularly useful for diagnosing issues in complex systems, as it allows developers to reconstruct the sequence of operations leading up to a problem. Static kernel tracing and user-level statically defined tracing (USDT) are examples of tracing techniques[^1]. Tracing differs from profiling in that it captures more granular information over time rather than aggregating performance metrics. #### Monitoring Monitoring involves continuously observing the health and performance of a running system. Unlike benchmarking, which measures performance under controlled conditions, monitoring tracks real-time metrics such as CPU usage, memory consumption, disk I/O, and network traffic. Monitoring tools alert administrators when thresholds are exceeded or anomalies are detected, enabling proactive issue resolution. While monitoring does not provide the same level of detail as profiling or tracing, it offers ongoing visibility into system behavior[^3]. #### Key Differences - **Purpose**: Benchmarking establishes performance baselines; profiling identifies bottlenecks; tracing records event sequences; monitoring observes system health. - **Granularity**: Tracing captures fine-grained details, while profiling aggregates data. Monitoring provides high-level overviews. - **Use Case**: Benchmarking is ideal for comparing systems, profiling for optimizing code, tracing for debugging, and monitoring for operational oversight. ```python # Example of a simple benchmarking script import time def benchmark_function(func, *args): start_time = time.time() func(*args) end_time = time.time() return end_time - start_time def example_function(n): for _ in range(n): pass execution_time = benchmark_function(example_function, 1000000) print(f"Execution Time: {execution_time} seconds") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值