继续复习

1620-7  唐大智《2016年12月23日》[连续第八十三天总结]

标题:继续复习

关键词:题目二个

内容(A)

写程序出结果:

#include<iostream.h>
void main(void )
{
     char res[10]={0};
     int i=0,x=3456,rem;
     do{
           rem=x%16;
           x=x/16;
           if(rem<10)res[i]='0'+rem;
           else res[i]='A'+rem-10;
           i++;
        }while(x!=0);
         i--;
         for(;o>=0;i--)cout<<res[i];
         cout<<endl;
}
输出 D80.

(B)

#include<iostream.h>
void main()
{
      int a[]={100,300,500},x=0;
      int *p1=a+2,*p2=&x;
      while(p1>=a){
           *p2+=*p1;
           p1--;
           cout<<x<<endl;
       }
}
(C)明日计划:冲刺最后一天。


好的,我可以为您提供相应的代码。以下是一个简单的实现,可以进行随机选择单词和保存错误单词的功能。 ```python import random import csv def select_words(file_path, num_words): # 从txt文件中随机选择num_words个单词 with open(file_path, 'r') as f: words = f.read().split() selected_words = random.sample(words, num_words) return selected_words def save_wrong_words(wrong_words, file_path): # 保存错误的单词到csv文件 with open(file_path, 'a', newline='') as f: writer = csv.writer(f) writer.writerow(wrong_words) def main(): file_path = 'words.txt' num_words = 5 wrong_words_file = 'wrong_words.csv' selected_words = select_words(file_path, num_words) print('请背诵以下单词:') for word in selected_words: print(word) input_words = input('请输入您背诵的单词,以空格分隔:').split() wrong_words = [word for word in input_words if word not in selected_words] if wrong_words: print('以下单词背诵错误:') for word in wrong_words: print(word) save_wrong_words(wrong_words, wrong_words_file) else: print('恭喜您,所有单词背诵正确!') if __name__ == '__main__': main() ``` 在该代码中,我们首先定义了两个函数:`select_words` 和 `save_wrong_words`。`select_words` 函数接受一个txt文件路径和要选择的单词数量作为参数,然后从文件中随机选择指定数量的单词。`save_wrong_words` 函数接受一个包含错误单词的列表和一个csv文件路径作为参数,将错误单词写入csv文件中。 在 `main` 函数中,我们首先调用 `select_words` 函数选择一些单词并提示用户进行背诵。然后,我们使用 `input` 函数获取用户输入的单词,并使用列表推导式找到所有错误的单词。如果有错误的单词,则将它们打印出来并保存到指定的csv文件中。否则,打印一条恭喜消息。 请注意,此代码仅为示例,可能需要根据您的具体需求进行更改和扩展。同时,为了保护您的隐私,我不会透露您的任何要求或信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值