日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

【牛客网】迷途的牛牛 C++

發布時間:2024/2/28 c/c++ 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【牛客网】迷途的牛牛 C++ 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

思路1 復雜版

4個左轉可以抵消
4個右轉可以抵消
1個左轉和一個右轉可以抵消

#include<iostream> #include<string> using namespace std;int main() {int n;string str;cin >> n >> str;int l = 0;//L的個數int r = 0;//R的個數for (int i = 0; i < n; i++) {str[i] == 'L' ? l++ : r++;}l %= 4;//4個L抵消r %= 4;//4個R抵消l = (l - r) >= 0 ? (l - r) : (l - r) + 4;//L與R合并,取正switch (l) {case 3:cout << "E"; break;case 2:cout << "S"; break;case 1:cout << "W"; break;case 0:cout << "N"; break;}system("pause"); }

思路2 簡化版

只看左轉次數,右轉直接和左轉抵消

#include<iostream> #include<string> using namespace std;int main() {int n;string str;cin >> n >> str;int l = 0;//L的個數for (int i = 0; i < n; i++) {str[i] == 'L' ? l++ : l--;}l %= 4;//4個L抵消l = l >= 0 ? l : l + 4;//L取正switch (l) {case 3:cout << "E"; break;case 2:cout << "S"; break;case 1:cout << "W"; break;case 0:cout << "N"; break;} }

總結

以上是生活随笔為你收集整理的【牛客网】迷途的牛牛 C++的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。