本帖最后由 Gin_Q 于 2020-8-3 19:48 编辑
- // 设1个中文占2个字符
- // 电子屏字符循环播出
- #include <stdio.h>
- #include<windows.h>
- #define W 36 // 定义电子屏的宽度
-
- int main(void)
- {
- static char str[100][3];
- static char s[1024];
- while (1)
- {
- printf("\r请输入字符串:");
- scanf("%s",s);
- system("cls");
- if (s) break;
-
- }
- register int i=0,j=0;
- char *p = s;
- for (i=0;*p;i++)
- {
- p = s+i;
- if (*(s+i) < 0)
- {
- strncpy(str[j],p,2);
- j++;i++;
- }
- else
- {
- strncpy(str[j],p,1);
- j++;
- }
- }
-
- for (i=0; i<W; i++) if (! *str[i]) strcpy(str[i], " ");
- for(i = 0;i<=W ;i++)
- {
- printf("\r");
- for(j=0;j < W;j++) printf("%s",*(str + (i + j) % W));
- Sleep(100);
- if (i==W) i=0;
- //system("pause >nul");
- }
- return 0;
- }
复制代码 #python3- '''
- @ 进度条打印
- '''
-
- #coding=utf-8
-
- from time import sleep
- from multiprocessing import Process,Queue
-
- q = Queue()
-
- ico = [
- ['0%',''],
- ['10%','X'],
- ['20%','XX'],
- ['30%','XXX'],
- ['40%','XXXX'],
- ['50%','XXXXX'],
- ['60%','XXXXXX'],
- ['70%','XXXXXXX'],
- ['80%','XXXXXXXX'],
- ['90%','XXXXXXXXX'],
- ['100%\n','XXXXXXXXXX'],
- ]
-
- def run(q):
- while True:
- if not q.empty():
- t = q.get()
- if t == None: break
- print('\r{:<10}{}'.format(t[1],t[0]),end='',flush=True)
-
-
- if __name__ == "__main__":
- n = 0
- arr = []
- p = Process(target=run,args=(q,))
- p.start()
- print('开始计算 1 累加到 10 :')
- for i in range(11):
- n += i
- q.put(ico[i])
- sleep(0.2)
- q.put(None)
- p.join()
- print('计算 1 累加到 10 完成:{}'.format(n))
-
复制代码
|